C#/SQL Server: Login failed when connecting from remote machine

1

I've got an SQL Server 2008 Express set up on one machine and am trying to connect with my C# app to the server from another machine (both Win 7). The server machine has a user account for me in the system. The SQL Server is configured to use Windows Authentication. Firewall on the server machine has inbound rules to accept ports 1433 for TCP and 1434 for UDP and also accept the server's exe.

The problem: I cannot connect to the server. Whatever connection string I use I get errors:

System.Data.SqlClient.SqlException (0x80131904): Login failed for user 'SERVINGMACHINE\wally'.

or

System.Data.SqlClient.SqlException (0x80131904): Login failed. The login is from an untrusted domain and cannot be used with Windows authentication.

An example of my connection string:

SqlConnection myConnection = new SqlConnection("Integrated security=true;" +
  @"user id=SERVERMACHINE\wally;" +
  //"password=testpasswd;" +
  @"server=10.127.40.1,1433\SQLEXPRESS;" + 
  "Trusted_Connection=true;" +
  "database=nscm_db; " +
  "connection timeout=30");

I've commented out the password since it's allegedly not used for trusted connection.

When the app and the server are on the same machine the connection works fine.

What am I doing wrong?

windows-7
sql-server-2008
windows
asked on Server Fault Apr 21, 2012 by Val

2 Answers

0

You're misunderstanding what "Integrated Security=true" means.

"True" means use the credentials of the current process, and do not specify a username or password.

SqlConnection.ConnectionString Property
http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.connectionstring%28v=vs.100%29.aspx

"...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."

answered on Server Fault Apr 21, 2012 by Greg Askew
0

If you are using trusted logins, you should not provide any login name. Connections will be made using whatever you are logged in with.

Are the two computers members of the same Active Directory domain? If not, you can try creating the same account on both machines, including matching passwords. I am not sure if that works under Windows 7, I have not tried it since the early days of Windows XP or maybe even Windows 2000.

The quickest way out for you is probably just to create SQL Server account and use that.

answered on Server Fault Apr 21, 2012 by darin strait

User contributions licensed under CC BY-SA 3.0