King Wardak
King Wardak

Reputation: 21

Connecting C# with SQL Server Database in a Local Area Network (LAN)

I have created a C# application that I want to run on a Local Area Network, so that different PCs can install my application and access the database stored on Server PC. Now the point is that i am really a rookie when it comes to Network connectivity. Right now I use this code to connect to my database:

public SqlConnection con = new SqlConnection("Data Source=localhost; Initial Catalog= my_db; Integrated Security= True");

Can you guys help me with this? Thanks in Advance.

P.S. Do i have to install SQL Server Management Studio in Server PC?

Upvotes: 1

Views: 4027

Answers (3)

Alons
Alons

Reputation: 31

Try to use with Server IP address

string connectionString = "SERVER=123.123.1.12;" + "UID=xxxxxxx;" + "PWD=xxxxxxx;" + "DATABASE=xxxxxx;" + "Encrypt=FALSE;";

Here the IP Address is just for Demo only.Use your own.I'm currently have this, and works 100% fine.

Upvotes: 1

Rita Chavda
Rita Chavda

Reputation: 191

"Server=ServerName;Initial Catalog=DBName;User ID=sa;Password=Pass;"

here ServerName you find in your SQl server->Object Explorer where you find IP address or name ,Initial Catalog is your DB name

Upvotes: 0

Viktor A
Viktor A

Reputation: 146

Obviously with your current connection string your clients will be trying to connect to their own computers. You should use something like "Server=yourServerAddress;Database=yourDataBase;User Id=username; Password=password;" instead.

Upvotes: 0

Related Questions