2013-02-25 240 views
0

我一直试图解决这个错误一段时间没有成功。我想知道有人可以帮助我开始确定可能导致此错误的原因。疑难解答SqlException(0x80131904)

我试图调查的PHP脚本调用它没有帮助。另外,我无法找到这条路径:提前

[SqlException (0x80131904): A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)] 
    System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +6256377 
    System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +245 
    System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, SqlConnection owningObject) +6270399 
    System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, Int64 timerExpire, SqlConnection owningObject) +181 
    System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(String host, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, Int64 timerStart) +6271242 
    System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance) +6271208 
    System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance) +354 
    System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection) +703 
    System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options) +54 
    System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject) +6272472 
    System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject) +81 
    System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) +1657 
    System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +88 
    System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +6275911 
    System.Data.SqlClient.SqlConnection.Open() +258 
    Inventory1.welcome.Page_Load(Object sender, EventArgs e) in C:\Inetpub\wwwroot\Inventory1\welcome.aspx.cs:55 
    System.Web.UI.Control.OnLoad(EventArgs e) +132 
    System.Web.UI.Control.LoadRecursive() +66 
    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2428 

非常感谢

Inventory1.welcome.Page_Load(Object sender, EventArgs e) in C:\Inetpub\wwwroot\Inventory1\welcome.aspx.cs:55 

完全错误信息!

回答

0

这是一个SqlException。背后Welcome.aspx页的文件中的代码

A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)

Page_Load方法试图打开到SQL服务器的连接,它是失败的。检查你的连接字符串。

基本上你应该给SqlConnection对象一个valid connection string,然后再打开它来查询数据库。防爆;

using(SqlConnection cnn = new SqlConnection("valid_connection_string")) 
{ 
    //Other stuff 
    cnn.Open(); 
    //Execute the command 
} 

This web site具有各种不同类型的连接字符串。

+0

感谢您的回复。所描述的错误消息的奇怪之处在于'C:\ Inetpub \ wwwroot \ Inventory1 \ welcome.aspx.cs:55'是服务器上不再存在的路径。我新建的'welcome.aspx'路径存在,它似乎像sql试图访问过时的路径。 – AnchovyLegend 2013-02-25 15:10:04

+0

接下来,我无法访问'C:\ Inetpub \ wwwroot \ Inventory1 \ welcome.aspx.cs:55' – AnchovyLegend 2013-02-25 15:11:12

+0

您是否在IIS或Asp.net服务器上运行该网站?看来错误路径来自IIS根文件夹。 – Kaf 2013-02-25 15:14:02