zack_falcon
zack_falcon

Reputation: 4376

C# Log In Failed for User '' The user is not associated with a trusted SQL Server connection (LAN)

Exactly what the title says.

Here's my connection string:

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

The program is supposed to fill-in the Server Name, in front of the "\". Running it on my computer, where SQL Server is installed, that piece of code works fine.

Running it on a computer connected to mine via a network, well, the problem in the title happens. I've set my SQL Server to Mixed (SQL and Windows Authentication), and the problem still happens. I've also enabled the TCP/IP and all other stuff in the Server config manager.

I know that one of the answers is to 'make a user' or something, and provide a username and password of some sort, but if I'm to fiddle around in the SQL Server Management, that means whoever would want to install and run my program would also have to mess with a very user-unfriendly SQL server. Something that my professors will not allow.

So I humbly ask, is there some way I can eliminate this problem by using codes in C#?

Basically, what my professors would want is:

Thanks for any and all answers.

Upvotes: 0

Views: 1255

Answers (2)

Jive Boogie
Jive Boogie

Reputation: 1265

If I understand correctly you want to have an app that will run on lots of diff computers with all of them connecting to a single SQL Server Database on a server. If all the computers are part of the same Domain or Workgroup then you can use Windows Integrated Security otherwise you will have no choice but to use SQL Server Authentication. You can just set up a single SQL Server account on the server with the appropriate permissions and then in C# you can create the connections string like this.

        SqlConnectionStringBuilder connString = new SqlConnectionStringBuilder();
        connString.DataSource = ServerHere;
        connString.InitialCatalog = DBHere;
        connString.IntegratedSecurity = false;
        connString.UserID = SQLUser;
        connString.Password = SQLPassword;

        return connString.ConnectionString;

and your app can take it from there.

Upvotes: 1

4b0
4b0

Reputation: 22323

May its work.

Data Source=xxx.xxx.xxx.xxx,1433

ip of your pc and port.

Upvotes: 0

Related Questions