简体   繁体   中英

provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)

i am developing a web application in visual studio 2012. and i have added a database file named as Database1.mdf into App_Data folder and i have given following connection string

Data Source=(LocalDB)\v11.0;AttachDbFilename="E:\asp.net mvc\storage\storage\App_Data\Database1.mdf";Integrated Security=True

after that i have written the code for inserting the data but at that i am getting the error like

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)

is there any mistake in the connection string? Please help me in htis

Usually, for me, this indicates that SQL Server hasn't been configured correctly to receive remote calls. There are three things to check.

  1. Your server instance is named correctly and you have permissions to it
  2. That you are configured to receive remote connections
  3. That SQL server is open on the the protocols you want to use

To check the second one, open up SQL Management Studio and select Properties on the server. Then check under "Connections" that "Remote Server Connections" is enabled.

To check the third, open up SQL Server Configuration Manager and make sure that "Client Protocols" TCP/IP is enabled as well as Named Pipes (depending on your network setup).

您的连接字符串应这样写:

     connectionString="DataSource=.\SQLEXPRESS; InitialCatalog=Database; AttachDBFilename=|DataDirectory|\Database.mdf; Integrated Security=SSPI;" 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM