Error 28000: Login failed for user DOMAIN\\user with pyodbc

后端 未结 8 1422
慢半拍i
慢半拍i 2020-12-06 05:00

I am trying to use Python to connect to a SQL database by using Window authentication. I looked at some of the posts here (e.g., here), but the suggested methods didn\'t see

相关标签:
8条回答
  • 2020-12-06 05:25

    Trusted_connection=no did not helped me. When i removed entire line and added UID, PWD parameter it worked. My takeaway from this is remove

    0 讨论(0)
  • 2020-12-06 05:26
    import pyodbc   #For python3 MSSQL
    
    cnxn = pyodbc.connect("Driver={SQL Server};"   #For Connection
                       "Server=192.168.0.***;"
                       "PORT=1433;"
                       "Database=***********;"
                       "UID=****;"
                       "PWD=********;")
    cursor = cnxn.cursor()                        #Cursor Establishment
    cursor.execute('select site_id from tableName')   #Execute Query
    
    rs = cursor.fetchall() 
    print(rs)
    
    0 讨论(0)
  • 2020-12-06 05:27

    I had similar issue while connecting to the default database (MSSQLSERVER). If you are connecting to the default database, please remove the

    database='DATABASENAME',

    line from the connection parameters section and retry.

    Cheers, Deepak

    0 讨论(0)
  • 2020-12-06 05:27

    A slightly different use case than the OP, but for those interested it is possible to connect to a MS SQL Server database using Windows Authentication for a different user account than the one logged in.

    This can be achieved using the python jaydebeapi module with the JDBC JTDS driver. See my answer here for details.

    0 讨论(0)
  • 2020-12-06 05:35

    I tried everything and this is what eventually worked for me:

    import pyodbc
    driver= '{SQL Server Native Client 11.0}'
    
    cnxn = pyodbc.connect(
        Trusted_Connection='Yes',
        Driver='{ODBC Driver 11 for SQL Server}',
        Server='MyServer,1433',
        Database='MyDB'
    )
    
    0 讨论(0)
  • 2020-12-06 05:39

    Try this cxn string:

    cnxn = pyodbc.connect('DRIVER={SQL Server};SERVER=localhost;PORT=1433;DATABASE=testdb;UID=me;PWD=pass')
    

    http://mkleehammer.github.io/pyodbc/

    0 讨论(0)
提交回复
热议问题