另一个用户正在使用她在python会话中创建的数据库,我们称之为user_db。我在SSMS中删除了一个不同的数据库,我们称之为other_db。删除other_db后,她的脚本声称无法找到user_db的db id。如果她删除user_db并重新创建它,则问题仍然存在。如果她使用像new_user_db这样的新名称,她的脚本会再次运行。
对我来说,似乎unixodbc / freetdbs / pyodbc / python端的东西是缓存数据库ID。任何人都可以告诉我哪些工具可能导致问题并可能解决它?
错误:
pyodbc.ProgrammingError:('42000',“[42000] [FreeTDS] [SQL Server]找不到数据库ID(id_number)
编辑: 软件版本 pyodbc - 4.0.16 centos - 6.6 unixODBC - 2.2.14 freeTDS - 0.91
可重复通过: 用户1(在Python中):
conn = pyodbc.connect(cxnstring)
cursor = conn.cursor()
cursor.execute('CREATE DATABASE test')
cursor.execute('CREATE DATABASE test_1')
cursor.execute('CREATE TABLE test_1.dbo.test_table (column_1 INT)')
cursor.execute('SELECT * FROM test_1.dbo.test_table')
用户2(在SSMS中):
DROP DATABASE test_1
用户1(在Python中):
conn = pyodbc.connect(cxnstring)
cursor = conn.cursor()
cursor.execute('CREATE DATABASE test_1')
cursor.execute('CREATE TABLE test_1.dbo.test_table (column_1 INT)')
cursor.execute('SELECT * FROM test_1.dbo.test_table')
编辑更正的SQL语法
答案 0 :(得分:0)
我遇到的问题与最近由另一个连接丢弃数据库后查询Information_Schema有关。跑步' DBCC FREEPROCCACHE'每次查询db的Information_Schema似乎都可以解决问题。