Application Scenario:
1,serverversion a problem, "sqlcnt.serverversion" raises the type "System.InvalidOperationException" Exception
2, on the string also thought that the data Source should be. Or local, this actually depends on the situation.
Problem Description:
In the environment (SQL Server2008, Win7, 32-bit, VS2010 development system), connecting to the database fails with the "is that a network-related or instance-specific error occurs when SQL Server establishes a connection, the server is not found or unreachable, verify that the instance name is correct, and that SQL Server is configured to allow remote connections. (provider:named Pipes provider,error:40-Unable to open SQL Server connection)”。 As shown in the following:
Solution:
Now that the error has been stated, it may be because the instance name is incorrectly written. Then there are two possibilities, one is that the SQL service is not open, and the second is that the SQL instance name is wrong.
1. Confirm that the service is turned on, we find the Service Setup interface (Control Panel--management tools--services) as shown in: Locate the SQL Server service and confirm that the service is turned on. (Note: SQL is installed with the default instance name MSSQLSERVER, learning version SQLExpress)
2, viewing the project's Web. config file, detecting the database connection string instance name (the value of data Source) is correct.
For example: I check to see the configuration of data Source =. The point (.) indicates the use of the MSSQLServer instance, but as can be seen from the above, my SQL uses the Express version database, so the correct configuration should be data Source =. \SQLExpress Some people will say, I also know when to use the dot (.), what to use. \SQLExpress, or the custom instance name. That's better, just take the SQL test. Open SQL Server Management Studio, test our data in the login, set the server name to Point (.), as shown in: Set the server name to Point (.), Prompt for errors, and the error is the same as above, but we replace ". \SQLExpress" will be able to log in normally.
the situation where this problem occurs:
In general, the instance name is rarely misconfigured, but if it is a team project, usually everyone is running normally, but one day suddenly the code and the database moved to another computer to run, due to different computer SQL database version of the difference (there is an enterprise version of the study version) This problem may occur, And, of course, you have to change the instance name to something else when you install SQL. In addition to the problem with the instance name or the service is not turned on, there is a situation where the error message says that the remote connection may not be allowed. This needs to be "peripheral configuration Tool" to modify it.
Extended reading:
Microsoft's description of the issue
(RPM) in a SQL Server 2016,visual Studio 2017 environment, the connection database fails repeatedly, and the problem on the ConnectionString