.net sql client / asp.net超时问题 [英] .net sql client/asp.net Timeout Issue

查看:55
本文介绍了.net sql client / asp.net超时问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个唠叨的SQL客户端/连接超时问题,我真的可以使用一些帮助。 我有一个使用DAL的大型ASP.NET Web应用程序(请参阅DAL中的以下存储过程类并调用代码)。 我遇到的问题是,在几个小时无故障运行后,ASP.NET应用程序开始挂起并在数据被更新,删除或插入时显示错误(选择不会导致错误)通过一个sproc。 所有选择工作都很好。  SQL Server(尽可能接近)在任何给定时间(例如<10)显示合理数量的打开连接,即使在错误条件下也是如此。 我也看不到哪里有锁。 此外,无论您运行哪个sproc来更新/删除/插入,都会发生超时错误,因此它不是单个表问题。

Web服务器和数据库服务器之间有防火墙,但最常见港口是开放的。 我不确定这是否会解决这个问题,但我想我会提到它。 系统的总体负载非常小(一次少于几个用户)。 我在StoreProcedure类的Dispose方法中放置了一行代码,它在关闭连接时写入事件日志(只是为了确保它被调用),并且连接似乎正在关闭。 我可以通过分离数据库并重新附加数据库或重新启动SQL来将应用程序恢复到工作状态。 在该应用程序中更改web.config文件(或任何文件)并强制执行新的JIT编译并不能解决问题。 我的预感是有一个SQL Server锁定情况或一些我不知道的.net Sql Client事件。 我花了很多时间来审查关于连接泄漏的帖子等等,但这似乎并不适合特定的法案,除了生成的超时错误类似于一个。 这是某种交易问题吗? 我没有以任何方式使用明确的交易。

 


以下是设置: 错误是

******************************* BEGIN ERROR ******* ************************************************** ********
超时已过期。操作完成之前经过的超时时间或服务器没有响应。
描述:执行当前Web请求期间发生了未处理的异常。请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。

异常详细信息:System.Data.SqlClient.SqlException:超时已过期。操作完成之前经过的超时时间或服务器没有响应。

源错误:

在执行当前Web请求期间生成了未处理的异常。可以使用下面的异常堆栈跟踪来识别有关异常的起源和位置的信息。 

堆栈跟踪:


[SqlException:超时已到期。 操作完成前经过的超时时间或服务器没有响应。]
   System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior cmdBehavior,RunBehavior runBehavior,Boolean returnStream)+740
   System.Data.SqlClient.SqlCommand.ExecuteNonQuery()+196
--------------------------------- -----------------------------------------------
.....

******************************* END ERROR **** ************************************************** ***********

 


******************* ************开始服务器信息*********************************** ******************************数据库服务器操作系统:Windows 2003
数据库服务器:SQL Server 2000 SP4

Web服务器:Windows Server 2000 Service Pack 4
版本信息:Microsoft .NET Framework版本:1.1.4322.2032; ASP.NET版本:1.1.4322.2032
System.Data.DLL版本:1.1.4322.2032
************************ ******* END SERVER INFO **************************************** *************************

 

 


*********************************开始编号************* ************************************************** **
我的DAL课程看起来像这样

 密封的内部课程StoredProcedure:IDisposable
  {
   private SqlCommand command;

   /// < summary>
   /// 构建新的StoredProcedure。
   /// < param name ='sprocName'>
   ///要执行的存储过程的名称< / param>
   /// < param name ='parameters' >
&NBSP;&NBSP;的SqlParameter的的///阵列存储过程< / PARAM>
&NBSP;&NBSP; ///< /总结>

&NBSP;&NBSP ; public StoredProcedure(string sprocName,SqlParameter [] par ameters)
   {
    command = new SqlCommand(sprocName,new SqlConnection(ConfigManager.DALConnectionString));
    command.CommandType = CommandType.StoredProcedure;
   
    foreach(参数中的SqlParameter参数)
     command.Parameters.Add(参数);

&NBSP;&NBSP;&NBSP; command.Parameters.Add(
&NBSP;&NBSP;&NBSP;&NBSP;新的SqlParameter( "返回值",
&NBSP;&NBSP;&NBSP ;   SqlDbType.Int,
      / * int size * / 4,
      ParameterDirection.ReturnValue,
      / * bool isNullable * / false,
      / * byte precision * / 0,
   ;&NBSP;&NBSP;&NBSP; / *字节规模* / 0,
&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; / *串srcColumn * /的String.Empty,
&NBSP;&NBSP;&NBSP;&NBSP ;  DataRowVersion.Default,
   &nb sp;  / * value * / null
    )
   );
    command.Connection.Open ();
  }

   public void Dispose()
   {
    if(command != null)
    {
     command.Connection.Close();
     command.Connection .Dispose();
     command.Dispose();
     command = null;
   }
  }

   /// < summary>
   ///执行此存储过程。
  ;  /// < returns>存储过程返回的Int32值< / returns>
   ///< / summary>

   public int Run()
   {
    if(command == null)
    抛出新的ObjectDisposedException(GetType() .FullName);
    command.ExecuteNo nQuery();
    return(int)command.Parameters ["ReturnValue"] .Value;
  }
 }

 

调用它的样本看起来像这样......
 
   public int DeleteActivityLogEntry(int intActivityLogID)
   {
   
    int retval = new int();
   
   ; 尝试
    {
     //创建参数数组
     SqlParameter [] parameters =
     {
      new SqlParameter("@ intActivityLogID",SqlDbType.Int,4)
     };

     //设置参数值和方向
     parameters [0] .Value = intActivityLogID;
&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;
&NBSP;&NBSP;&NBSP;&NBSP; //运行&NBSP;&NBSP;&NBSP;&NBSP ; sproc = new StoredProcedure("spDelete_ActivityLog",参数);
     retval = sproc.Run();
     sproc.Dispose() ;
    
   }
    catch(SqlException e)
    {
    
     throw; //引发错误的简单方法
   }

    return retval;
  }
** *****************************结束代码******************* **********************************************


任何帮助都将不胜感激。

谢谢。

 

解决方案

< blockquote>我收到同样的错误。任何提示帮助都非常感谢。

谢谢
Pratap


I have a nagging sql client/connection timeout problem that I could really use some help with.  I have a large ASP.NET web application that uses a DAL (see below stored procedure class in DAL and calling code).  The problem that I'm having is that after running trouble-free for a few hours, the ASP.NET application begins to hang and show the error below WHEN DATA IS BEING UPDATED,DELETED, OR INSERTED (SELECTS do NOT cause the error) by a sproc.  ALL of the selects work just fine.  The SQL Server (as near as I can tell) is showing a reasonable number of open connections at any given time (e.g < 10), even under error conditions.  I also cannot see where there are locks anywhere.  Also, the timeout error occurs regardless of which sproc you are running to update/delete/insert so it's not a single table issue.

There is a firewall between the web server and the database server, but most common ports are open.  I'm not sure if this plays in to the problem at all but I thought I'd mention it.  The overall load on the system is very minimal (less than a few users at a time).  I placed a line of code in the StoreProcedure class' Dispose method which writes the event log when it closes connections (just to make sure that it's being called), and the connections appear to be getting closed.  I can restore the application to working status by detaching the db and re-attaching it, or by restarting SQL.  Making a change to the web.config file (or any file for that matter) in that app, and forcing a new JIT compilation does NOT remedy the problem.  My hunch is that there's a SQL Server locking situation or some .net Sql Client thing that I'm not aware of.  I've spent a lot of time reviewing posts on connection leaks, and the like, but this just doesn't seem to fit the bill specifically except that the timeout error that is generated resembles one.  Is this a transaction issue of some sort?  I'm not using explicit transactions in any way.

 


Here's the setup:  The error is

*******************************BEGIN ERROR*****************************************************************
Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. 

Stack Trace:


[SqlException: Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding.]
   System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream) +740
   System.Data.SqlClient.SqlCommand.ExecuteNonQuery() +196
--------------------------------------------------------------------------------
.....

*******************************END ERROR*****************************************************************

 


*******************************BEGIN SERVER INFO*****************************************************************
Database Server OS: Windows 2003
Database Server: SQL Server 2000 SP4

Web Server: Windows Server 2000 Service Pack 4
Version Information: Microsoft .NET Framework Version:1.1.4322.2032; ASP.NET Version:1.1.4322.2032
System.Data.DLL Version: 1.1.4322.2032
*******************************END SERVER INFO*****************************************************************

 

 


*******************************BEGIN CODE*****************************************************************
My DAL class looks like this

 sealed internal class StoredProcedure : IDisposable
 {
  private SqlCommand command;

  /// <summary>
  /// Construct a new StoredProcedure.
  /// <param name='sprocName'>
  /// Name of the stored procedure to execute</param>
  /// <param name='parameters'>
  /// Array of SqlParameter's to the stored procedure</param>
  /// </summary>

  public StoredProcedure( string sprocName, SqlParameter[] parameters )
  {
   command = new SqlCommand( sprocName, new SqlConnection( ConfigManager.DALConnectionString ) );
   command.CommandType = CommandType.StoredProcedure;
   
   foreach ( SqlParameter parameter in parameters )
    command.Parameters.Add( parameter );

   command.Parameters.Add(
    new SqlParameter( "ReturnValue",
     SqlDbType.Int,
     /* int size */ 4,
     ParameterDirection.ReturnValue,
     /* bool isNullable */ false,
     /* byte precision */ 0,
     /* byte scale */ 0,
     /* string srcColumn */ string.Empty,
     DataRowVersion.Default,
     /* value */ null
    )
   );
   command.Connection.Open();
  }

  public void Dispose()
  {
   if ( command != null )
   {
    command.Connection.Close();
    command.Connection.Dispose();
    command.Dispose();
    command = null;
   }
  }

  /// <summary>
  /// Execute this stored procedure.
  /// <returns>Int32 value returned by the stored procedure</returns>
  /// </summary>

  public int Run()
  {
   if ( command == null )
    throw new ObjectDisposedException( GetType().FullName );
   command.ExecuteNonQuery();
   return ( int )command.Parameters[ "ReturnValue" ].Value;
  }
 }

 

And a sample of a call to it looks like this...
 
  public int DeleteActivityLogEntry(int intActivityLogID)
  {
   
   int retval = new int();
   
   try
   {
    // Create parameter array
    SqlParameter[] parameters =
    {
     new SqlParameter("@intActivityLogID", SqlDbType.Int, 4)
    };

    // Set parameter values and directions
    parameters[ 0 ].Value = intActivityLogID;
          
    // Run the stored procedure
    sproc = new StoredProcedure("spDelete_ActivityLog", parameters);
    retval = sproc.Run();
    sproc.Dispose();
    
   }
   catch( SqlException e )
   {
    
    throw; //simple way to raise an error
   }

   return retval;
  }
*******************************END CODE*****************************************************************


Any help would be appreciated.

Thanks.

 

解决方案

I am getting the same error. Any prompt help highly appreciated.

Thanks
Pratap


这篇关于.net sql client / asp.net超时问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆