I want to make a simple application which its databse is on another PC in my LAN,What do I need to do to make such connection?
I can make connections on the local PC.What do need to do to make a remote one?
I want the exact syntax of the connection string(and what its different parts are):
This is the connection string on the local computer:

Data Source=SETMC252TAHA\SQLEXPRESS;Initial Catalog=MYD;Integrated Security=True

How should I change it?
Does it need a usrname and password?if yes how can I make them in SQLSERVER.

Do I need to change some settings in SQLSEREVR?(cause I used several syntaxes in C# but none of them worked.)

(Another questions Shouldn`t an application with this

CODE]Data Source=SETMC252TAHA\SQLEXPRESS;Initial Catalog=MYD;Integrated Security=True

connection string easily work on other PCs on my LAN?)
Cause it has the server name.

TANX

Dani AI

Generated

Short checklist for a remote SQLEXPRESS client on a LAN: enable the TCP/IP protocol for the SQLEXPRESS instance, make the SQL Server Browser available or assign a fixed TCP port, open the appropriate firewall ports (instance port and UDP 1434 for the Browser), and choose authentication (Windows integrated only if the client can present a Windows account the server trusts; otherwise use SQL logins). ’s note about the two auth styles is correct; ’s pointer toward connection-string examples is helpful — below are the practical steps and examples you can apply.

Enable TCP/IP and make the instance discoverable: open SQL Server Configuration Manager → SQL Server Network Configuration → Protocols for your instance → enable TCP/IP, then (if you want predictable ports) set a static TCP port on the IP Addresses tab and restart the Database Engine. For named instances (SQLEXPRESS) you typically either run SQL Server Browser or use a fixed port. (learn.microsoft.com)

Firewall and connection-string notes: allow inbound TCP for whatever port your instance uses (default 1433 for a default instance; named instances are often dynamic) and allow UDP 1434 if you rely on SQL Server Browser. For a client that avoids Browser/dynamic-port issues, connect with an IP+port form; for example:

Data Source=tcp:192.168.1.50,1433;Initial Catalog=MYD;User ID=appuser;Password=YourStrongPassword;

The tcp: prefix and ,port form are the reliable way to target a specific TCP port. (learn.microsoft.com)

If you can’t use Windows Authentication across the machines, enable SQL Server (Mixed) authentication and create a SQL login mapped to the database. Example T‑SQL (run as an admin):

-- on master
CREATE LOGIN [appuser] WITH PASSWORD = 'S3cureP@ssw0rd';
-- in target DB
USE MYD;
CREATE USER [appuser] FOR LOGIN [appuser];
ALTER ROLE db_datareader ADD MEMBER [appuser];

Give the app only the minimum role it needs (avoid db_owner if possible). Use SSMS to switch authentication mode or run the CREATE LOGIN/CREATE USER statements shown. (learn.microsoft.com)

Troubleshooting tips: ping the server, verify the SQL error log for "Server is listening on" to find the port, test with SSMS or sqlcmd using IP,port, and if you still see timeouts check the server firewall and whether SQL Browser (UDP 1434) is blocked. (learn.microsoft.com)

Recommended Answers

All 2 Replies

Standard Security:

1- "Data Source=Your_Server_Name; Initial Catalog= Your_Database_Name; UserId=Your_Username; Password=Your_Password;"

2-"Server=Your_Server_Name; Database=Your_Database_Name; UserID=Your_Username; Password=Your_Password; Trusted_Connection=False"

Trusted connection:

1. "Data Source=Your_Server_Name; Initial Catalog=Your_Database_Name; Integrated Security=SSPI;"

2- "Server=Your_Server_Name; Database=Your_Database_Name; Trusted_Connection=True;"

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.