如何使用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了,为什么还不能连接,还有这个错误?
如何才能进行本地连接啊?
我用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,这样就可以正常访问数据库了。
SQLEXPRESS是你的数据库的实例名字
本文探讨了使用C#连接本地SQLServer2005实例的方法及连接字符串配置。通过调整连接字符串中的服务器名称部分,成功解决了无法连接的问题。
38

被折叠的 条评论
为什么被折叠?



