一个应用程序突然无法连接到数据库了。其他应用程序连接正常

问题描述:

我的一个应用程序不再连接到数据库服务器。这个应用程序已经投入使用了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://*.com/questions/1391503/a-network-related-or-instance-specific-error-发生,虽然建立一个连接) - 我的猜测可能是您的机器上的防火墙。 – Bridge

+0

因此,应用程序使用当前的Windows登录用户登录?也许是另一个帐户? –

我最近遇到过类似的问题。运行特定项目无法连接,但其他项目和应用程序可能会连接。我重新启动,问题没有了。尝试重新启动。

+0

重新启动了服务器和客户端,但仍然出现同样的问题 –

+0

我发现应用程序在链接服务器上查询数据库(我没有写应用程序,所以我错过了这个)在链接服务器上,一个事务被阻塞,阻塞了这个数据库上的所有其他事务,重新启动链接服务器后,事情回到了正常状态湖@大家:感谢支持! –

根据我在这种情况下当内部异常显示“访问被拒绝”时的经验,可以确定您的程序运行的账户无法访问数据库。

建议您检查您是否正在模拟任何帐户,并且是否有权访问数据库[在我的情况下,用于模拟(在web.config中)的帐户密码已更改它给了我这个错误]