[英]connecting to MSSQL DB using SQLAlchemy throwing error type 08001
I've got this code: 我有以下代码:
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()
I'm getting this error: 我收到此错误:
sqlalchemy.exc.DBAPIError: (Error) ('08001', '[08001] [Microsoft][ODBC SQL Server Driver][DBNETLIB]SQL Server does not exist or access denied. (17) (SQLDriverConnect); [01000] [Microsoft][ODBC SQL Server Driver][DBNETLIB]ConnectionOpen (Connect()). (53)') None None
sqlalchemy.exc.DBAPIError :(错误)(“ 08001”,“ [08001] [Microsoft] [ODBC SQL Server驱动程序] [DBNETLIB] SQL Server不存在或访问被拒绝。(17)(SQLDriverConnect); [01000] [ Microsoft] [ODBC SQL Server驱动程序] [DBNETLIB] ConnectionOpen(Connect())。(53)')无无
I ran this query on my DB 我在数据库上运行了此查询
select db_name()
and got this O/P 并得到了这个O / P
1. master
Can someone explain what is wrong in my logic? 有人可以解释我的逻辑有什么问题吗?
I found the issue, the firewall on the server was rejecting my connection. 我发现了问题,服务器上的防火墙拒绝了我的连接。 I disabled the Firewall to check the connection and I got the connection.
我禁用了防火墙以检查连接并得到连接。 I've to make an exception in the firewall rule to allow the connection to the SQL Server TCP/IP Port.
我必须在防火墙规则中设置例外,以允许连接到SQL Server TCP / IP端口。
One can refer to this link for steps to do so http://blogs.msdn.com/b/walzenbach/archive/2010/04/14/how-to-enable-remote-connections-in-sql-server-2008.aspx 可以参考此链接以获取执行此操作的步骤http://blogs.msdn.com/b/walzenbach/archive/2010/04/14/how-to-enable-remote-connections-in-sql-server-2008 .aspx
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.