Connection String Error (error : 40)

孤人 提交于 2019-12-02 20:48:11

问题


I have installed SQL Server 2012 Express on a Windows Server 2008 Machine. The name of the machine is "THEMACHINE". While installation, I set SQL Server 2012 as "Default Instance". Now I set my connection string like this :

<add name="BooksContext" providerName="System.Data.SqlClient" connectionString="Data Source=THEMACHINE;Initial Catalog=newdb; User ID=sa; Password=123456"/>

But 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)"}

I checked that database is running. Can you tell me what I'm doing wrong?Thanks.


回答1:


Reference: Creating and Configuring Universal Data Link (.udl) Files

Do following to Test connection and generate connection string,

1) Create query.udl file in the desktop

2) Double click the file to open and do the following

3)Open the Query.udl in notepad, you will find the connectionstring.




回答2:


Change Data Source=THEMACHINE to Data Source=THEMACHINE\SQLEXPRESS. Also check that the database service is running.



来源:https://stackoverflow.com/questions/28344367/connection-string-error-error-40

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!