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