Remote connection to MS SQL - Error using pyodbc vs success using SQL Server Management Studio

前端 未结 4 458
轮回少年
轮回少年 2021-01-18 21:00

I have a MS SQL database in the same network but in other computer. Using the SQL Server Management Studio (SSMS) Express, I can find the database and connect without proble

4条回答
  •  粉色の甜心
    2021-01-18 21:11

    Try specifying the port:

    import pyodbc
    
    server = r"xxxER\xxxSQLSERV"
    db = "xxxDB"
    user = "xxx"
    password = "xxxx"
    port = "1433"
    conn = pyodbc.connect('DRIVER={SQL Server};SERVER=' + server + ';PORT=' + port + ';DATABASE=' + db +';UID=' + user + ';PWD=' + password)
    

    If you're still having issues, try using the IP or FQDN of the server.

提交回复
热议问题