简体   繁体   中英

Error while connecting to SQL server 2005

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)

I am using .NET framework provider for SQL Server and Visual Studio 2008.

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

What am I missing here?

AttachDbFilename should be the path to the database filed (generally a.mdf) that you will be using.

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

I know external references are bad, but it really does not get better than this:

http://www.connectionstrings.com/

as they say

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

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)

By default SQL Server Express disables remote connections via TCP/IP and Named Pipes, so you will need to enable these protocols in the SQL Server Configuration Manager (Start --> Programs --> Microsoft SQL Server 2008 --> Configuration Tools).

在此处输入图像描述

I also agree with Hogan about ConnectionStrings.com great site!

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