简体   繁体   English

使用SQLAlchemy抛出错误类型08001连接到MSSQL DB

[英]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.

相关问题 将sqlalchemy连接到mssql时出错“不支持ODBC数据类型-150” - Error “ODBC data type -150 is not supported” when connecting sqlalchemy to mssql (Python) 使用 SQLalchemy 连接 mssql 数据库并使用它 - (Python) Connecting mssql database using SQLalchemy and using it 使用sqlalchemy连接到mssql数据库时遇到问题 - Having trouble connecting to an mssql database using sqlalchemy 使用mssql在0.6迁移中的sqlalchemy日期类型 - sqlalchemy date type in 0.6 migration using mssql 使用 Flask-SQLAlchemy 和 pyodbc 连接到 Flask 中的 MSSQL - Connecting to MSSQL in Flask using Flask-SQLAlchemy and pyodbc Python-通过连接到MSSQL DB来获取数据的数据类型处理 - Python - Data type handling for data fetched by connecting to the MSSQL DB 使用 sqlalchemy 连接到 postgresql 时出错 - Error while connecting to postgresql using sqlalchemy [SqlAlchemy][mssql][tls1.2] 如何使用来自 windows 的 pyodbc 为连接到 MS SQL 服务器的 SqlAlchemy 强制执行 TLS 1.2? - [SqlAlchemy][mssql][tls1.2] How to enforce TLS 1.2 for SqlAlchemy connecting to MS SQL Server using pyodbc from windows? 使用 python 和 sqlalchemy 连接到 DB2 时出错 - 需要 SQLAlchemy 格式的连接信息 - Error connecting to DB2 with python and sqlalchemy - Connection info needed in SQLAlchemy format 使用 SQLAlchemy 连接到数据库 - Connecting to database using SQLAlchemy
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM