Reputation: 835
I have a database on a local network.
I can connect to the database in SSMS:
But when I want to connect to the database by this connection string in c#:
"Data Source=192.168.0.3,14330;Network Library=DBMSSOCN;Initial Catalog=master;Integrated Security=True;User ID=sa;Password=123456789;"
I get the following error:
Login failed. The login is from an untrusted domain and cannot be used with Windows authentication.
Upvotes: 1
Views: 7166
Reputation: 81493
Your are telling sql server to use integrated security, ie windows security, however you trying to use a username and password
turn integrated security off, see the below example
"Data Source=192.168.0.3,14330;Network Library=DBMSSOCN;Initial Catalog=master;Integrated Security=False;User ID=sa;Password=123456789;"
Pertinent information
If User ID and Password are specified and Integrated Security is set to true, the User ID and Password will be ignored and Integrated Security will be used.
You can find more information on connection strings here, SqlConnection.ConnectionString Property
Update
maybe this question may help you more How to get the connection String from a database
Update 2
For more in depth troubleshooting, there is a great resource here How to Troubleshoot Connecting to the SQL Server Database Engine
Upvotes: 2