我有这个代码:
from sqlalchemy.engine import create_engine
engine = create_engine('mssql+pyodbc://sa:Passw0rd@172.19.201.75/master.db', echo=True)
connection = engine.connect()
connection.execute(
"""
CREATE TABLE users (
username VARCHAR PRIMARY KEY,
password VARCHAR NOT NULL
);
"""
)
connection.execute(
"""
INSERT INTO users (username, password) VALUES (?, ?);
""",
"foo", "bar"
)
result = connection.execute("SELECT username FROM users")
for row in result:
print "username:", row['username']
connection.close()
我收到此错误:
sqlalchemy.exc.DBAPIError: (Error) ('08001', '[08001] [Microsoft][ODBC SQL Server Driver][DBNETLIB]SQL Server 不存在或访问被拒绝。(17) (SQLDriverConnect); [01000] [ Microsoft][ODBC SQL Server 驱动程序][DBNETLIB]ConnectionOpen (Connect()).(53)') 无 无
我在我的数据库上运行了这个查询
select db_name()
并得到了这个 O/P
1. master
有人可以解释我的逻辑有什么问题吗?