0

I ran into this issue where I couldn't connect to SQL server using the credentials . I can connect when using trusted connection = yes . Am I doing something wrong here ? Should something be added or concidered ?

conn = pyodbc.connect('Driver={SQL Server Native Client 11.0};'
                  'Server=1070010-01;'
                  'Database=test_DB;'
                  'Uid =sa;'
                  'Pwd =SDTK-1111;'
                 )

I have also tried replacing Uid and Pwd with username and password . I have also tried adding trusted_connection = no In all the above cases , I get this error :

conn = pyodbc.connect('Driver={SQL Server Native Client 11.0};'
pyodbc.InterfaceError: ('28000', "[28000] [Microsoft][SQL Server Native Client 11.0][SQL Server]Login failed for user ''. (18456) (SQLDriverConnect); [28000] [Microsoft][SQL Server Native Client 11.0]Invalid connection string attribute (0); [28000] [Microsoft][SQL Server Native Client 11.0][SQL Server]Login failed for user ''. (18456); [28000] [Microsoft][SQL Server Native Client 11.0]Invalid connection string attribute (0)")
jarlh
  • 42,561
  • 8
  • 45
  • 63
  • A trusted connection is the method used by Windows Authentication to connect to your database, Microsoft has a good article on the subject [here](https://learn.microsoft.com/en-us/sql/relational-databases/security/choose-an-authentication-mode?redirectedfrom=MSDN&view=sql-server-ver15) – Umar.H Apr 16 '20 at 10:52
  • It is already answered here [https://stackoverflow.com/questions/53273146/python-pyodbc-connect-to-sql-server-using-sql-server-authentication] – Rajnish kumar Apr 16 '20 at 10:57
  • Does this answer your question? [Python pyodbc connect to Sql Server using SQL Server Authentication](https://stackoverflow.com/questions/53273146/python-pyodbc-connect-to-sql-server-using-sql-server-authentication) – Rajnish kumar Apr 16 '20 at 11:00
  • Thank you . It seems like it was a formatting issue . – sameh grami Apr 16 '20 at 11:35

1 Answers1

0

try this , string was not well formatted

  conn = pyodbc.connect('Driver={SQL Server Native Client 11.0}; Server=1070010-01; uid=sa; pwd=SDTK-1111; Database = test_DB; Trusted_Connection=No;')
Manish Chaudhary
  • 498
  • 6
  • 14