Click here to Skip to main content
15,884,176 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This is my connection string to connect the database via LAN

C#
SqlConnection con = new SqlConnection("Data Source=192.168.1.2,1433;Initial Catalog=test;Integrated Security=True;Trusted_Connection=True");


but this code not working for me.......
The error is

Login failed for user 'pc name\Guest'
Posted

 
Share this answer
 
I guess you're using the server in a workgroup network. You cannot connect to the server in windows authentication mode. You must install the server in mixed mode and login using an account name (sa or other) and password.

use
server=MACHINE_NAME\INSTANCE_NAME; uid=sa; pwd=xxx;

There are 2 other things you must do before connecting
1) Enable sql browser service
2) Go to Configuration Tools->SQL Server Configuration Manager
Select
SQL Server Configuration->Protocols for [INSTANCE]
and enable TCP/IP (& restart the server)

==============================
However, if you're on a domain network & you have installed the SQL Server on the domain controller, you may login using windows authentication after adding logins.
To add logins, you may use
CREATE LOGIN [MACHINE_NAME\USER_NAME] FROM WINDOWS WITH DEFAULT_DATABASE=[master]
 
Share this answer
 
Comments
Dave Kreskowiak 5-Mar-12 11:41am    
A 4 for the pretty correct solution, but a -1 for even mentioning using the SA account for an application connection. That's a MONSTEROUS security violation!
Check if there is login and password for that PC.

If yes then include the UserName and Password in the connection string

Put User ID=sa;
 
Share this answer
 
v2
Comments
saravana__ 5-Mar-12 5:32am    
I am using window authendication mode to connect the sqlserver
Aniket Yadav 5-Mar-12 7:41am    
try this
Dave Kreskowiak 5-Mar-12 11:39am    
YOU TOLD HIM TO USE THE SUPERUSER ACCOUNT??
YOU NEVER USER THIS ACCOUNT FOR AN APPLICATION CONNECTION!!

Yes, I know I'm yelling - it's for a reason.
try this
C#
Data Source=10.11.1.1;Initial Catalog=databasename;Persist Security Info=True;User ID=sa;Password=s123
 
Share this answer
 
ConnectionString is missing userID, password and providername attributes.

connectionString="Data Source=192.168.1.2:1433;Initial Catalog=test;Integrated Security=True;Trusted_Connection=True";User ID=user;Password=pass;providerName="System.Data.EntityClient"
 
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