Configuring SQL Server 2016 Express On LAN For C# Connection String
Configuring SQL Server 2016 Express On LAN For C# Connection String
26.1k 0 7
Introduction
In this article, I will share my experience about con guring SQL Server 2016 Express on LAN
for SQL connection using my C# application’s connection string. I’m sure there are many
guides out there on this topic already. But, despite reading those while con guring it myself,
I still hit some errors that need minutes or hours to resolve. So, I decided to document the
process here for my own documentation, and for others who would like to do the same
thing.
Background
I was developing a C# WPF desktop application that connects to the local instance of SQL
Server 2016 Express. There was no problem connecting to the local instance of SQL Server
2016 Express using standard SQL Server connection string:
Server=.\SQLEXPRESS;Database=MyDatabase;User ID=MyUser;Password=MyPassword
But when my application went for testing, and it needed to connect to an SQL Server 2016
Express instance to a computer located on my LAN with the following connection string -
Server=192.168.1.100\SQLEXPRESS;Database=MyDatabase;User
ID=MyUser;Password=MyPassword
- there was an error message saying that I couldn’t connect to the SQL Server instance
because it was not found on my LAN. I was sure the root cause of the error is the SQL Server
2016 Express con guration, and also, the computer con guration where my SQL Server
2016 Express was installed.
Before we continue further, let’s de ne the scopes. In any computer system con guration,
there are many possibilities that can cause some cases easy to resolve, but not for some
others. In other words, it depends on the speci c scenario on hand. In my case, the
following software, OS, and LAN con guration are used as scopes:
https://www.c-sharpcorner.com/article/configuring-sql-server-2016-express-on-lan-for-c-sharp-connection-string/ 1/8
7/5/2020 Configuring SQL Server 2016 Express On LAN For C# Connection String
So, here is my step by step guide for con guring SQL Server 2016 Express on my database
server so, that my C# application in the network can use that database.
1. Make sure the Server properties are set to “Allow remote connections to this server”.
Usually, this step is unnecessary since SQL Server 2016 Express already sets this value
by default. Nevertheless, if we want to make sure, we use SQL Server Management
Studio (SSMS) on the local database server.
Just click on the database instance, for example (local)\SQLEXPRESS, and then click
Properties. On the Server Properties page, select Connections page, and then make
sure the setting for “Allow remote connections to this server“ is checked.
https://www.c-sharpcorner.com/article/configuring-sql-server-2016-express-on-lan-for-c-sharp-connection-string/ 2/8
7/5/2020 Configuring SQL Server 2016 Express On LAN For C# Connection String
Become a member
C# Corner Login
2. From the Start menu, choose “SQL Server 2016 Con guration Manager”. Expand the
“SQL Native Client 11.0 Con guration (32 bit)”, click on “Client Protocols”, on the right
pane, right-click on “TCP/IP”, and then choose "Enable" from the context menu.
https://www.c-sharpcorner.com/article/configuring-sql-server-2016-express-on-lan-for-c-sharp-connection-string/ 3/8
7/5/2020 Configuring SQL Server 2016 Express On LAN For C# Connection String
4. After enabling TCP/IP in “Protocols for SQLEXPRESS”, from the same context menu,
choose Properties to open “TCP/IP Properties” window. Click on the “IP Addresses” tab,
then scroll down to the bottom of the page. In “IPAll” section, clear the value for “TCP
Dynamic Port”, and ll the value of “TCP Port” with 1433. (You can use other port
number for SQL Server, but 1433 is the standard one).
https://www.c-sharpcorner.com/article/configuring-sql-server-2016-express-on-lan-for-c-sharp-connection-string/ 4/8
7/5/2020 Configuring SQL Server 2016 Express On LAN For C# Connection String
6. From Windows Start menu, type “services” to open Services window. Scroll down until
you nd “SQL Server Browser” service. Change the startup-type of the service to
"Automatic", and then, start the service. This step is necessary if we want to use
connection string to connect to a named instance of SQL Server service without
specifying the port number.
7. The next step is to con gure the rewall. If you turn o Windows Defender Firewall on
your database server, then you don’t have to con gure this setting. Otherwise, open
“Windows Defender Firewall” from Windows Control Panel, then choose "Advanced
settings" on the left pane. Note that in previous Windows version, the name of
https://www.c-sharpcorner.com/article/configuring-sql-server-2016-express-on-lan-for-c-sharp-connection-string/ 5/8
7/5/2020 Configuring SQL Server 2016 Express On LAN For C# Connection String
Become a member
C# Corner Login
The objective of this step is to allow inbound connections to port 1433 TCP used by
SQL Server service, and port 1434 UDP used by SQL Server
Post Browser service.
Ask Question
8. In “Windows Defender Firewall with Advanced Security” window, add two new rules in
“Inbound Rules” section. In the rst step of “New Inbound Rule Wizard”, choose “Port”.
https://www.c-sharpcorner.com/article/configuring-sql-server-2016-express-on-lan-for-c-sharp-connection-string/ 6/8
7/5/2020 Configuring SQL Server 2016 Express On LAN For C# Connection String
10. Repeat step 9 for UDP protocol, and port number 1434.
11. Now, you should be able to use SQL Server Management Studio from another server,
and also, use it in C# code connection strings.
Troubleshooting
If you have already performed all the steps above but still not able to connect to the SQL
Server, what you should do? Here are the troubleshooting steps that I performed to resolve
such situation.
1. Make sure that our client PC is located in the same network with the database server
machine. Use "ipcon g" command to enquire local PC IP address, and then, use ping
command to inquire database server’s IP address. When doing ping command, it’s
better to turn o Windows Defender Firewall on database server machine temporarily.
2. Make sure that the database server’s port 1433 (TCP) and 1434 (UDP) are up and
running. We can use network debugging tool such as Nmap to do port scanning on
database server machine.
3. It’s also worth trying to turn o Windows Defender Firewall on the database server
while we are troubleshooting. This temporary step eliminates the possibility of
Windows Defender Firewall preventing inbound connections to the database server.
4. Use SQL Server Management Studio (SSMS) to connect to the database server before
using it in a connection string. If SSMS can detect database server, you should have no
problem using it in a connection string.
5. Specify port in the connection string. This port part is necessary if we didn’t enable the
SQL Server Browser service.
Server=192.168.1.100\SQLEXPRESS,1433;Database=MyDatabase;User
ID=MyUser;Password=MyPassword
Summary
In this article, I have explained the steps necessary to con gure SQL Server 2016 Express for
C# connection string.
Embed Analytics and Dashboards into your product with a JavaScript SDK. Free trial.
C# Connection String LAN For C# SQL Server SQL Server 2016 Express
https://www.c-sharpcorner.com/article/configuring-sql-server-2016-express-on-lan-for-c-sharp-connection-string/ 7/8
7/5/2020 Configuring SQL Server 2016 Express On LAN For C# Connection String
10 Delegates In C# Explained
View All
About Us Contact Us Privacy Policy Terms Media Kit Sitemap Report a Bug FAQ Partners
https://www.c-sharpcorner.com/article/configuring-sql-server-2016-express-on-lan-for-c-sharp-connection-string/ 8/8