PYODBC--Data source name not found and no default driver specified

后端 未结 15 1825
暖寄归人
暖寄归人 2020-11-28 13:01
import pyodbc
connection = pyodbc.connect(\'Driver = {SQL Server};Server=SIWSQL43A\\SIMSSPROD43A;\'
                            \'Database=CSM_reporting;Trusted_Conn         


        
15条回答
  •  青春惊慌失措
    2020-11-28 13:25

    Do not put a space after the Driver keyword in the connection string.

    This fails on Windows ...

    conn_str = (
        r'DRIVER = {SQL Server};'
        r'SERVER=(local)\SQLEXPRESS;'
        r'DATABASE=myDb;'
        r'Trusted_Connection=yes;'
    )
    cnxn = pyodbc.connect(conn_str)
    

    ... but this works:

    conn_str = (
        r'DRIVER={SQL Server};'
        r'SERVER=(local)\SQLEXPRESS;'
        r'DATABASE=myDb;'
        r'Trusted_Connection=yes;'
    )
    cnxn = pyodbc.connect(conn_str)
    

提交回复
热议问题