我正在使用连接字符串成功地从sqlalchemy连接到sqlexpress实例:
connection_str = 'mssql+pyodbc://mylaptop\sqlexpress/master?driver=SQL+Server+Native+Client+11.0&trusted_connection=yes'如何连接到非默认端口上的sql实例,这可能吗?
connection_str = 'mssql+pyodbc://mylaptop\sqlexpress:1433/master?driver=SQL+Server+Native+Client+11.0&trusted_connection=yes'这是我所期望的连接字符串,但这将返回错误:
(pyodbc.OperationalError) ('08001', '[08001] [Microsoft][SQL Server Native Client 11.0]TCP Provider: No connection could be made because the target machine actively refused it.\r\n (10061) (SQLDriverConnect); [08001] [Microsoft][SQL Server Native Client 11.0]Login timeout expired (0); [08001] [Microsoft][SQL Server Native Client 11.0]A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online. (10061)我已经尝试过一些与端口的组合,但没有看到合法的组合?
发布于 2020-05-05 19:30:02
在SQLAlchemy连接URI中,可以通过以下两种方式之一指定Server实例
server_name\instance_name,orserver_name:port你应该只使用其中一种。如果指定了instance_name,则server_name上的service服务将提供端口号。如果您指定了端口,那么实际的instance_name并不重要,因为端口号已经知道了。
https://stackoverflow.com/questions/61617483
复制相似问题