简体   繁体   中英

Unable to connect to a remote MS SQL Server and access it's database via. python

I have tried to establish a connection with a remote Microsoft SQL server.

Shown below is the python code I've used to connect to the server.

conn = pyodbc.connect('DRIVER={ODBC Driver 13 for SQL Server};Server=server,1443;DATABASE=master;UID=xx;PWD=xx')

The error shown is as follows:

pyodbc.OperationalError: ('08001', '[08001] [Microsoft][ODBC Driver 13 for SQL Server]TCP Provider: The wait operation timed out.\\r\\n (258) (SQLDriverConnect); [08001] [Microsoft][ODBC Driver 13 for SQL Server]Login timeout expired (0); [08001] [Microsoft][ODBC Driver 13 for SQL Server]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. (258)')

The server is configured to allow remote connections, but it is of no difference. Any help with regards to this problem would be highly appreciated.

A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible.

The error shows when the server could not be reached or the port might be blocked by the firewall. Can you connect using SQL Server management studio to the MSSQL? If not please check that the server is accepting TCP connections.

This question shows steps to check SQL server settings for the same: https://stackoverflow.com/a/15417069/9135407

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM