`
lipan61
  • 浏览: 45279 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

Named Pipes Provider, error: 40 - Could not open a

阅读更多

如果用SQLServer的SQLEXPRESS版本的话,连接时经常回遇到这个问题,查了很多终于找到了解决方法。

The typical error when dealing with Express includes:

a. User is not aware of SqlExpress was installed as a named instance, consequently, in his/her connection string, he/she only specify ".","localhost" etc instead of ".\SqlExpress" or "\Sqlexpress".

b. Np was disabld by default after installing SqlExpress.

c. If Sqlexpress was installed on the remote box, you need to enable remote connection for Express.

其中a的.\SqlExpress必须写在web.config文件中,如:

<connectionStrings>
<add name="NorthwindConnectionString" connectionString="Data Source=.\SqlExpress;Initial Catalog=Northwind;User ID=sa;Password=test"
   providerName="System.Data.SqlClient" />
</connectionStrings>

再用ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString把connectionStrings从应用程序中读出来。如果直接把.\SqlExpress写在应用程序中如:SqlConnection conn = new SqlConnection("data source=.\ SqlExpress;initial catalog=Northwind;user id=sa;password=test")这样也是有错误的!

Please read the following blog for best practice of connecting to SqlExpress.

http://blogs.msdn.com/sql_protocols/archive/2006/03/23/558651.aspx

分享到:
评论
1 楼 figure_he_he 2010-07-26  
谢谢提供的方法、

相关推荐

Global site tag (gtag.js) - Google Analytics