Click here to Skip to main content
15,903,012 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
SQL Server 2005 over LAN with c# windows application- login failed user. the user is not associated with a trusted sql server connection.
.........
I am attempting to use the following code to establish a connection to a SQL
Server database 2005 by using visual studio 2013/c#. However, when I execute the code, I receive the following
error:

login failed user . the user is not associated with a trusted sql server connection.
.
my database on the server it is work in microsoft access project but is not worked
when i Used c#.

when change my user domain to admin it is worked.

What I have tried:

//string connectionString = "Data Source=xxx.x.x.x,1433;Initial Catalog=Database;Integrated Security=SSPI;User ID=user1;Password=123456";
//string connectionString = "Data Source=xxx.x.x.x;Initial Catalog=Database2;Integrated Security=True";
// string connectionString = "Data Source=xxx.x.x.x;Database=Database2;User Id=user1;Password=123456;Persist Security Info=False";
// string connectionString = "Provider=SQLNCLI;Server=xxx.x.x.x;Database=Database2;Trusted_Connection=yes;";
// string connectionString = "Provider=SQLNCLI;Server=xxx.x.x.x;Database=Database2;Trusted_Connection=yes;MARS Connection=True;";
// string connectionString = " Provider=sqloledb;Data Source=xxx.x.x.x,1433;Network Library=DBMSSOCN;Initial Catalog=Database2;User ID=user1;Password=123456;";
string connectionString = " Provider=sqloledb;Data Source=xxx.x.x.x;Network Library=DBMSSOCN;Initial Catalog=Database2;User ID=user1;Password=123456;";
Posted
Updated 31-Aug-16 21:54pm
Comments
RickZeeland 22-Aug-16 6:37am    
Maybe this helps: http://blog.sqlauthority.com/2014/01/17/sql-server-fix-login-failed-for-user-username-the-user-is-not-associated-with-a-trusted-sql-server-connection-microsoft-sql-server-error-18452/
ZurdoDev 22-Aug-16 7:53am    
What is your question? You said, "when change my user domain to admin it is worked." So, you know it is a security problem that you need to fix. What do you want us to do?

1 solution

Hi Jon,

you can use either of this way
Standard Security
Server=myServerAddress;Database=myDataBase;User Id=myUsername;
Password=myPassword;

Trusted Connection
Server=myServerAddress;Database=myDataBase;Trusted_Connection=True;

Connection to a SQL Server instance
The server/instance name syntax used in the server option is the same for all SQL Server connection strings.

Server=myServerName\myInstanceName;Database=myDataBase;User Id=myUsername;
Password=myPassword;

you can refer "https://www.connectionstrings.com/sql-server/" for help.

if it will not help you please copy your code so we can debug for it.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900