农用三轮车调刹车视频:如何用C#连接到本地SQL Server 2005实例

来源:百度文库 编辑:杭州交通信息网 时间:2024/04/27 23:43:55
如何使用C#连接到本地SQL Server 2005实例?连接字符串sqlConnectionString该怎样写。比如我本地的SQL Server 2005实例名称是SQLEXPRESS,要连接到Northwind数据库。
我用connectionString ="server = localhost; database = Northwind; integrated security=SSPI",编译运行后。
系统总是提示无法连接的异常:
Unhandled Exception: System.Data.SqlClient.SqlException: An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this 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)

我已经启用了TCPIP,Named Pipes了,为什么还不能连接,还有这个错误?
如何才能进行本地连接啊?
我又试了一下。连接字符串中写 server = localhost\\SQLEXPRESS 或者 server = local\\SQLEXPRESS或者 server = .\\SQLEXPRESS,这样就可以正常访问数据库了。

为什么我一定要指明SQL Express的实例名才能正常访问呢?是不是设置一下系统变量就可以只指定server=localhost,就可以让系统自动找到实例?

应当如何设置呢?

connectionString ="server =(local); database = Northwind; integrated security=SSPI"
应该是server=. 或者是server =(local) 不应该是localhost

server =.(或在sqlgroup里登录用的名字);database=northwind;integrated security=SSPI"
你用localhost,那就意味着你本地机器在登录sql的时候用的名字就是localhost,这样也可以