⚠️ Common Error Message
When attempting to connect to SQL Server, you may encounter the following error:
"A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 – Error Locating Server/Instance Specified)"
If you receive this error, follow these steps to resolve it.
🔍 Step 1: Ensure SQL Server Accepts Remote Connections
Open SQL Server Management Studio
Right-click on the server name and select Facets
From the dropdown list, choose Server Configuration
Set the
RemoteAccessEnabled
property toTrue
🔄 Step 2: Check SQL Server Services
All SQL-related services should be running and set to start automatically. It is best to ensure all related services remain in a started state.
🔐 Step 3: Verify Connection String Format
Use a connection string similar to the following:
Public conn As SqlConnection = New SqlConnection("Data Source=192.168.0.2\SQLExpress;Network Library=DBMSSOCN;Initial Catalog=DatabaseName;User Id=sa;Password=MyPassword;")
Explanation:
Data Source=192.168.0.2\SQLExpress
specifies the server address and instanceNetwork Library=DBMSSOCN
instructs it to use TCP/IPInitial Catalog=DatabaseName
sets the target databaseUser Id
andPassword
provide authentication credentials
🔥 Step 4: Configure Windows Firewall
Go to Start > Run > Firewall.cpl
Open the Exceptions tab
Add the following items:
Port 1433
sqlbrowser.exe
sqlwriter.exe
sqlservr.exe
🌐 Step 5: Enable TCP/IP Protocol for SQL Server
Open SQL Server Configuration Manager
Navigate to SQL Server Network Configuration > Protocols for MSSQLSERVER
Double-click TCP/IP
Set the Enabled option to Yes under the Protocol tab
Go to the IP Addresses tab
For each IP you want to allow, set its Enabled value to Yes
✅ Final Notes
This guide was written based on two frustrating experiences with the same error. Recording the steps here helps avoid repeating lengthy research next time. There is no special reason beyond that.