3

Tried all sorts of variations to connect from python pyodbc to my local SQL Server

enter image description here

Also tried doing the \ escape

'Server=(LocalDB)\\MSSQLLocalDB;'
'UID=domain\\uname;'

but still get this error

I am able to connect to the same localdb from SSMS.

this is the error message screenshot

enter image description here

Dale K
  • 25,246
  • 15
  • 42
  • 71
AtuD
  • 83
  • 2
  • 11

2 Answers2

1

First you should choose between providing uid/password and Trusted_Connection I would suggest you to construct the connection string as follows:

"DRIVER={SQL Server};SERVER=localhost;DATABASE=TestDB;UID=$user;PWD=$password"

Furthermore, if localhost does not solve your issue you can use (local) also and for a named instance localhost\$instance_name, you do not have to put 2 backslashes. Last I would strongly suggest you to upgrade your driver to the latest version. As you can easily set it in the connection string as follows:

"DRIVER={ODBC Driver 17 for SQL Server};SERVER=localhost;DATABASE=TestDB;UID=$user;PWD=$password"

In addition you can check this link

mustafasencer
  • 723
  • 4
  • 12
1

Connecting to SQL Server Express Edition LocalDb requires an updated driver. The legacy ODBC driver can't do it. So either get the new ODBC Driver, or download SQL Server Express (the Windows Service package).

David Browne - Microsoft
  • 80,331
  • 6
  • 39
  • 67