Click here to Skip to main content
15,891,633 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Whenever i click the register the button i get this exception '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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)'.

SqlConnection con = new SqlConnection("Data Source=./SQLEXPRESS;AttachDbFilename=C:/... Security=True;Connect Timeout=30;User Instance=True; ");

con.Open();
Posted
Comments
Er. Ajay Chauhan 19-Feb-14 12:02pm    
which version of Windows OS, Visual Studio and SQL Server you are using?

check these things
1. Make sure your database engine is configured to accept remote connections(I you are using centralized database)
•Start > All Programs > SQL Server 2005 > Configuration Tools > SQL Server Surface Area Configuration
•Click on Surface Area Configuration for Services and Connections
•Select the instance that is having a problem > Database Engine > Remote Connections
•Enable local and remote connections
•Restart instance

2. Check the SQL Server service account
•If you are not using a domain account as a service account (for example if you are using NETWORK SERVICE), you may want to switch this first before proceeding

3.If you are using a named SQL Server instance, make sure you are using that instance name in your connection strings in your ASweb P.NET application
•Usually the format needed to specify the database server is machinename\instancename
•Check your connection string as well
 
Share this answer
 
Comments
Heyrbiar 20-Feb-14 10:08am    
When i click SQL Server Surface Area Configuration it says that "No SQL Server 2005 components were found on the specified computer. Either no components are installed, or you are not an administrator on this computer."
Basically, when you failed to connect to your SQL Server, the issue could be:
1) Network issue,
2) SQL Server configuration issue.
3) Firewall issue,
4) Client driver issue,
5) Application configuration issue.
6) Authentication and logon issue.

Based on the error message you didn't allow the remote connection to that machine so change the options in settings.

Check these
Steps to troubleshoot SQL connectivity issues[^]
SQL Server 2005 Connectivity Issue Troubleshoot - Part I[^]
Troubleshoot Connectivity Issue in SQL Server 2005 - Part II[^]
Troubleshoot Connectivity Issue in SQL Server 2005 - Part III[^]

BTW check this bunch also for future errors
 
Share this answer
 
make sure Your Server Name

run this
SQL
SELECT @@SERVERNAME



copy paste the server Name

SQL
SqlConnection con = new SqlConnection("Data Source=./SQLEXPRESS;AttachDbFilename=C:/... Security=True;Connect Timeout=30;User Instance=True; ");
 
Share this answer
 
v3
Comments
Heyrbiar 21-Feb-14 5:28am    
I tried it but i get same problem, please help
King Fisher 21-Feb-14 5:50am    
same error?
Heyrbiar 21-Feb-14 5:55am    
yeah
King Fisher 21-Feb-14 5:57am    
SELECT @@SERVERNAME
run this ,copy paste the server name ,then let me know what happend..

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