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

后端 未结 15 1652
暖寄归人
暖寄归人 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:05

    if any one are trying to access the database which is hosted in azure then try to give the driver as ODBC Driver 17 for SQL Server

    0 讨论(0)
  • 2020-11-28 13:11

    for error : pyodbc.InterfaceError: ('IM002', '[IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified (0) (SQLDriverConnect)')

    No space between the driver and event

    connection = Driver={SQL Server Native Client 11.0}; "Server=servername;" "Database=dbname;" "Trusted_Connection=yes;"

    0 讨论(0)
  • 2020-11-28 13:13

    You could try:

    import pyodbc
    # Using a DSN
    cnxn = pyodbc.connect('DSN=odbc_datasource_name;UID=db_user_id;PWD=db_password')
    

    Note: You will need to know the "odbc_datasource_name". In Windows you can search for ODBC Data Sources. The name will look something like this:

    Data Source Name Example

    0 讨论(0)
  • 2020-11-28 13:18

    I am also getting same error. Finally i have found the solution.

    We can search odbc in our local program and check for version of odbc. In my case i have version 17 and 11 so. i have used 17 in connection string

    'DRIVER={ODBC Driver 17 for SQL Server}'

    0 讨论(0)
  • 2020-11-28 13:19

    I have had the same error on python3 and this help me:

    conn = pyodbc.connect('DRIVER={ODBC Driver 17 for SQL Server};'
                          'SERVER=YourServerName;'
                          'DATABASE=YourDatabaseName;UID=USER_NAME;PWD=PASS_WORD;')
    

    remember python is case-sensitive so you have to mention DRIVER,SERVER,... in upper case. and you can visit this link for more information:

    https://docs.microsoft.com/en-us/sql/connect/python/pyodbc/step-3-proof-of-concept-connecting-to-sql-using-pyodbc?view=sql-server-ver15

    0 讨论(0)
  • 2020-11-28 13:20

    Create a DSN something like this (ASEDEV) for your connection and try to use DSN instead of DRIVER like below:

    enter code here
    import pyodbc
    cnxn = pyodbc.connect('DSN=ASEDEV;User ID=sa;Password=sybase123')
    mycur = cnxn.cursor()
    mycur.execute("select * from master..sysdatabases")
    row = mycur.fetchone()
    while row:
        print(row)
        row = mycur.fetchone()`
    
    0 讨论(0)
提交回复
热议问题