Log In Failed for User '' The user is not associated with a trusted SQL Server connection

Well, that's the full title of my problem.

I'm working on a C# program that supposedly could access a database run by SQL Server Express. I know the program works, because it works on the PC where I installed the SQL server. If I run the program from another PC on the network, though, the error happens.

Here's my connection string:

\SQLEXPRESS;Database=GGDBase;Integrated Security=SSPI;Trusted_Connection=true;Persist Security Info=False;

Variations include removing the Trusted_Connection, setting Trusted_Connection to 'false', and removing Persist Security Info. I also set the SQL Server Express authentication to 'Mixed' mode, and enabled the TCP/IP stuff. All return the error I noted above.

(The program adds the Computer name before the "\")

Some people say "add a username / password something something" while others say "add User Instance=true" (which has its own problems). All involve dealing with a very user-unfriendly SQL Server management program, and if I have to do it, I can imagine anyone who wants to use the program will have to fiddle with SQL Server as well. So, as you can guess, user-friendliness is a requirement, and typing in IP addresses and port numbers are out of question.

Is there some way I can resolve this problem via codes in C#? Perhaps I can add user instances from C# itself, or something?

Thanks in advanced.

Edited 5 Years Ago by zack_falcon: n/a

When you use a trusted connection, this will mean that the computer and the user running the application should be trusted by the SQL server.

Usually this can be accomplished putting the server, and the client computers in an Active Directory Domain, then loggin in the domain with a domain user.

Once you have all this, you must go to the SQl Server management console and in the Security/Logins folder add the users authorized to access the server. Each user must be Mapped to the databases he/sue must access and select the appropiate access level like datareader or datawriter or owner or ...

If you have the SQL server in mixed mode, then you should have a user called sa. Usually this user has no pasword, but to be a little more secure you must set a password. Also, to use this users on your connection string, the user must have a password. Lets assume that you put the passwrod H2+o

Then you can change the connection string to some thing like:

ServerName\SQLEXPRESS;Database=GGDBase;UserId=sa;Password=H2+o;Persist Security Info=False

Do not forget the servername if the server machine is other than the client machine.

Hope this helps

Edited 5 Years Ago by lolafuertes: n/a

Thanks. But it says "Keyword unsupported 'UserID'" :(. And what would I put in the password field if I didn't set any? Password=null?

Well, anyway, I need to test the data sent to / read from the database over the network. Is there any other way I can make sure that the program can connect to the server? I'm willing to forget about user friendliness for now.

SQL Authentication? Anything.

I tried the program on a Windows XP laptop (the OS of my previous test platform was Windows Vista). The server is still my computer (Windows 7).

Used this connection string:

\SQLEXPRESS;Database=GGDBase;Integrated Security=SSPI;Trusted_Connection=true;Persist Security Info=False;

Now it says: Login failed for user 'Server-Name\Guest'

Could I have some help, or pointer here, please? Really desperate for anything.

On your connection string, there is no info about the machine name supporting the SQLEXPRESS service.

Also atrusted connection is not allowed unless your server (W7) and your client(XP or Vista) are in the same active directory.
Integrated Security and Trusted_connection are mutually equivalent and only one is needed

In order to know the parameters you can use in your connection string visit this page.

My fault when writing the User Id as a unique word. Should be two.

When in the connection string I say ServerName, this will represent the actual name of your W7 machine. Please replace according.

Then the connection string should look like

ServerName\SQLEXPRESS;Database=GGDBase;User Id=sa;Password=;Persist Security Info=False

Hope this helps

This article has been dead for over six months. Start a new discussion instead.