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)
用ASP写的程序 数据库连接时出现的异常 有遇到过的没 ? 注意 是error :40 -
 谢谢了

解决方案 »

  1.   

    其中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")这样也是有错误的!