2011-04-30 163 views
0

An error occured while establishing a connection to the server. When connecting to the SQL server 2005, the failure may be caused by the fact that under the default settings SQL server does not allow remote connections. (provider: Named pipes provider, error: 40 - Could not open a connection to SQL server)错误,同时连接到SQL Server 2005

我使用的SQL Server .NET框架提供者和Visual Studio 2008

Data Source=.\SQLEXPRESS;AttachDbFilename="";Integrated Security=True;User Instance=True 

缺少什么我在这里?

回答

1

我知道外部引用是坏的,但它确实没有比这更好的:

http://www.connectionstrings.com/

,因为他们说

Server=.\SQLExpress;AttachDbFilename=c:\mydbfile.mdf;Database=dbname; Trusted_Connection=Yes; 
+0

伟大的网站,我经常使用它们。 – 2011-04-30 16:30:24

1

AttachDbFilename应该是您要使用的数据库字段(通常是.mdf)的路径。

Data Source=.\SQLEXPRESS;AttachDbFilename=c:\some.mdf;Integrated Security=True;User Instance=True 
1

An error occured while establishing a connection to the server. When connecting to the SQL server 2005, the failure may be caused by the fact that under the default settings SQL server does not allow remote connections. (provider: Named pipes provider, error: 40 - Could not open a connection to SQL server)

默认情况下,SQL服务器Express禁用通过TCP/IP和命名管道的远程连接,因此您需要启动在SQL Server配置管理器中启动这些协议(开始 - >程序 - > Microsoft SQL Server 2008 - >配置工具)。

enter image description here

我也同意霍根约ConnectionStrings.com伟大的网站!