1

I have a database on a local network.

I can connect to the database in SSMS:

enter image description here

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.

javad
  • 833
  • 14
  • 37
  • Set Integrated Security to False if you are providing USERNAME and PASSWORD in connection string. – Paresh J Dec 07 '14 at 06:24
  • @PareshJ I am try to use "Integrated Security=False" but get this error: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: TCP Provider, error: 0 - No such host is known.) – javad Dec 07 '14 at 06:43
  • 2
    javadaskari: Try enabling TCP/IP from sql server configuration manager. Goto SQL SERVER configuration Manager > SQLSERVER Network Configuration > Protocols > Enable TCP/IP – Paresh J Dec 07 '14 at 06:48
  • @PareshJ I've done it before – javad Dec 07 '14 at 06:57
  • Have you created SQL SERVER Rule in your firewall and try creating connection string using UDL file. Check this URL on how to use UDL: http://msdn.microsoft.com/en-in/library/e38h511e(v=vs.71).aspx – Paresh J Dec 07 '14 at 07:00

1 Answers1

2

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

Community
  • 1
  • 1
TheGeneral
  • 79,002
  • 9
  • 103
  • 141
  • I am try to use "Integrated Security=False" but get this error: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: TCP Provider, error: 0 - No such host is known.) – javad Dec 07 '14 at 06:38
  • Updated the answer, that might help you out a bit more – TheGeneral Dec 07 '14 at 06:49
  • 1
    @javadaskari "The server was not found or was not accessible": Double-check you've got the right server details, then, on the receiving end, ensure there aren't any firewalls blocking the connection. – jay_t55 Dec 07 '14 at 06:54
  • @jay_t55 My server details is right and firewall is off. – javad Dec 07 '14 at 07:00
  • @javadaskari Are you behind a NAT? Is the IP you listed here the actual one? Have you tried setting up port forwarding on your NAT Gateway? – jay_t55 Dec 07 '14 at 07:07
  • @jay_t55 My IP is static and actual one – javad Dec 07 '14 at 07:19
  • I used this connection string and my problem solved: "Data Source=192.168.0.3,14330;Initial Catalog=master;Persist Security Info=True;User ID=sa;Password=123456789;" – javad Dec 07 '14 at 16:04