2016-09-07 54 views
0

我的一個應用程序不再連接到數據庫服務器。這個應用程序已經投入使用了2年,沒有任何變化,並一直工作。一個應用程序突然無法連接到數據庫了。其他應用程序連接正常

我使用C#2010和MS SQL Server 2008 R2的

  • 我得到的錯誤:

"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: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)"

  • 內部異常: 「訪問被拒絕」

  • 使用完全相同的代碼,連接字符串,數據庫&數據庫服務器,我可以連接到另一個應用程序,沒有任何錯誤。

  • 我可以在服務器和數據庫上使用SSMS進行連接。

  • 該查詢(如果複製到SSMS)運行沒有問題。

CODE:

public DataTable QueryRetrieval(string sqlQuery) 
    { 
     // SP Command 
     SqlConnection Conn = new SqlConnection(this.connectionString); 
     this.Cmd = new SqlCommand(sqlQuery, Conn); 
     Cmd.CommandType = CommandType.Text; // Type of command 

     // Declarations (for scope purposes) 
     SqlDataAdapter Adapter = new SqlDataAdapter(Cmd); 

     DataTable DtResultSet = new DataTable(); 

     try 
     { 
      // Run the query 
      Conn.Open(); 
      Adapter.Fill(DtResultSet); 

      Conn.Close(); 

      // Return datatable 
      return DtResultSet; 
     } 
     catch (Exception Ex) 
     { 
      // Edit the message, rethrow exception 
      throw new Exception(
       "DataAccessor.QueryDataTable: Failed to run query '" + sqlQuery + "'\n\n" 
       + "Error message: \n--------------\n\n" + Ex.Message); 
     } 
     finally 
     { 
      // Remove the SQL command 
      Cmd.Dispose(); 
      Cmd = null; 

      // Remove the SQL data adapter 
      Adapter.Dispose(); 
      Adapter = null; 
     } 

    } 

連接字符串: 「服務器= MyServer的;數據庫= MYDB; Trusted_Connection = TRUE;」 (我替換了名稱。)

程序在Conn.Open()上失敗;當代碼碰到那條線時,我必須等待20或30秒,然後拋出異常。

服務器上未安裝任何更新。 我已經嘗試重新啓動服務器(整個服務器,而不是服務)。

有沒有人有線索可能導致這種情況發生?

+0

您是否能夠從託管應用程序的計算機ping DDBB服務器? – Oscar

+1

[建立與SQL Server的連接時發生網絡相關或特定於實例的錯誤]的可能重複(http://stackoverflow.com/questions/1391503/a-network-related-or-instance-specific-error-發生,雖然建立一個連接) - 我的猜測可能是您的機器上的防火牆。 – Bridge

+0

因此,應用程序使用當前的Windows登錄用戶登錄?也許是另一個帳戶? –

回答

0

我最近遇到過類似的問題。運行特定項目無法連接,但其他項目和應用程序可能會連接。我重新啓動,問題沒有了。嘗試重新啓動。

+0

重新啓動了服務器和客戶端,但仍然出現同樣的問題 –

+0

我發現應用程序在鏈接服務器上查詢數據庫(我沒有寫應用程序,所以我錯過了這個)在鏈接服務器上,一個事務被阻塞,阻塞了這個數據庫上的所有其他事務,重新啓動鏈接服務器後,事情回到了正常狀態湖@大家:感謝支持! –

0

根據我在這種情況下當內部異常顯示「訪問被拒絕」時的經驗,可以確定您的程序運行的賬戶無法訪問數據庫。

建議您檢查您是否正在模擬任何帳戶,並且是否有權訪問數據庫[在我的情況下,用於模擬(在web.config中)的帳戶密碼已更改它給了我這個錯誤]

相關問題