Connection String Error (error : 40)
Connection String Error (error : 40)
我已经在 Windows Server 2008 机器上安装了 SQL Server 2012 Express。机器的名称是"THEMACHINE"。安装时,我将 SQL Server 2012 设置为 "Default Instance"。
现在我像这样设置我的连接字符串:
<add name="BooksContext" providerName="System.Data.SqlClient" connectionString="Data Source=THEMACHINE;Initial Catalog=newdb; User ID=sa; Password=123456"/>
但是我得到了这个例外:
{"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)"}
我检查过数据库是 运行。你能告诉我我做错了什么吗?谢谢。
参考:Creating and Configuring Universal Data Link (.udl) Files
对 Test connection
和 generate
连接字符串执行以下操作,
1) 在桌面创建query.udl
文件
2) 双击文件打开并执行以下操作
3)用记事本打开Query.udl
,你会发现connectionstring
.
将数据源=THEMACHINE 更改为数据源=THEMACHINE\SQLEXPRESS。还要检查数据库服务是否为 运行.
我已经在 Windows Server 2008 机器上安装了 SQL Server 2012 Express。机器的名称是"THEMACHINE"。安装时,我将 SQL Server 2012 设置为 "Default Instance"。 现在我像这样设置我的连接字符串:
<add name="BooksContext" providerName="System.Data.SqlClient" connectionString="Data Source=THEMACHINE;Initial Catalog=newdb; User ID=sa; Password=123456"/>
但是我得到了这个例外:
{"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)"}
我检查过数据库是 运行。你能告诉我我做错了什么吗?谢谢。
参考:Creating and Configuring Universal Data Link (.udl) Files
对 Test connection
和 generate
连接字符串执行以下操作,
1) 在桌面创建query.udl
文件
2) 双击文件打开并执行以下操作
3)用记事本打开Query.udl
,你会发现connectionstring
.
将数据源=THEMACHINE 更改为数据源=THEMACHINE\SQLEXPRESS。还要检查数据库服务是否为 运行.