2013-02-25 238 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