如果用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
SQL Server Express 连接问题解决方案
本文解决了使用 SQL Server Express 版本时常见的连接问题,包括如何正确配置连接字符串,启用远程连接以及最佳实践。
930

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



