Verify that the instance name is correct

Source: Internet
Author: User
Tags config stack trace management studio sql server management sql server management studio connectionstrings

A network-related or instance-specific error occurred while establishing a connection with SQL Server. The server was not found or could not be accessed. Please verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named pipe provider, error:40-cannot open a connection to SQL Server)

Note: An unhandled exception occurred during the execution of the current WEB request. Check the stack trace for more information about the error and where the error occurred in the code.

Exception Details: System.Data.SqlClient.SqlException: A network-related or instance-specific error occurred while establishing a connection with SQL Server. The server was not found or could not be accessed. Please verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named pipe provider, error:40-cannot open a connection to SQL Server)


When this problem occurs, it is very simple, is a different version of the database, to connect the same method; note the following Scarlet Letter section. I used to use server=. DATABASE=JTJ; User Id=sa; password=


Changed into a server==. Sqlexpress;initial CATALOG=JTJ; User Id=sa; password=


It's been a long time.

1. Open the Sql2005 remote connection function, the opening method is as follows:

The Configuration tool->sql the server perimeter configuration-> service and the perimeter configuration of the connection-> open the Database engine node under the MSSQLSERVER node, select Remote Connection, and then recommend "use tcp/simultaneously" IP and Named pipes ", and then restart the database service after you are OK.

2. The login settings should read: SQL Server and Windows authentication mode, as set out below:

SQL Server Management Studio Manager->windows Authentication connection Server-> Object Explorer Select your data server-> Right-click-> Properties-> Security->sql Server and Windows authentication mode is selected.

3. Set a user name and password in SQL Server mode, as set out below:

(1) SQL Server Management Studio Manager->windows Authentication connection Server-> Object Explorer Select your data server-> expand Security on the server-> login name-> Right-click-> on the sa account to select General-> to change the password for the sa login account. This sets a user named SA with the password: sa123456.

(2) "Select Page" SELECT Status-> login modified to enable

4. Database connection string

There are several kinds of database connection strings, I believe you've seen them, they're all messed up.

Data server=. Sqlexpress;initial Catalog=northwind; User Id=sa; password=sa123456
Data server= server name sqlexpress;initial catalog=northwind; User Id=sa; password=sa123456
Data server=localhostsqlexpress;initial Catalog=northwind; User Id=sa; password=sa123456
Data Server=.;i Nitial Catalog=northwind; User Id=sa; password=sa123456
Data server= server name; Initial catalog=northwind; User Id=sa; password=sa123456
......

What exactly is that right? This is related to the database version, and if it is the SQL Server version of Express, you must have "SQLEXPRESS". And if the string is defined as a variable, VS2005 will also add a red wavy line under "" which prompts you that "s is an unrecognized escape sequence", so if the string is defined as a variable, it should be written as a server=. SQLEXPRESS

5. Register SQL Server database

The ASP.net SQL Server Setup Wizard Wizard appears when you run the aspnet_regsql command under the path "c:windowsmicrosoft.netframeworkv2.0.50727". Press two consecutive next step will appear SQL Server registration interface, fill in the database parameters you want to register. After the registration will be in your database a few more tables (figure):

5. Set the database connection string

Open iis-> The Default Web site or the virtual directory where the site is located click the Right button to select Properties-> select ASP.net tab-> Edit configuration-> Edit the "localsqlserver" database connection string on the General page:

Data server=. Sqlexpress;initial Catalog=northwind; User Id=sa; password=sa123456

6. Set up Web.config file

Add the following program to the Web.config file:
<connectionStrings>
<add name= "LocalSqlServer" connectionstring= "Data source=. Sqlexpress;initial Catalog=northwind; User Id=sa; password=sa123456 "providername=" System.Data.SqlClient "/>
</connectionStrings>

That's it. Here to test

1. Loose Connection test

Loose connection test using SqlDataSource

VS2005 Server Explorer Select database Right-click-> Select Modify Connection-> fill in Server name-> use SQL Server Authentication to populate user name SA and password sa123456-> Select or enter a database name: northwind- > Click to test the connection

Loose connection Test Connection success does not indicate that the database is connected OK, in the beginning I was hanging here, the loose connection test test connection success, but always can not read the contents of the database to the page.

2. Rigorous connectivity Testing

Select the Site menu->asp in VS2005. NET configuration into the ASP.net web Site Administration Tool-> Select provider-> Click AspNetSqlProvider Test, if the test is successful, the database set up completely correct, otherwise have to look at the beginning of the problem.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.