张文波(半空) 博客

交流

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

■环境说明:

数据库系统:Microsoft Server 2000 (Sp4)

操作系统:Microsoft Server 2003 (SP1)

开发环境:Microsoft  Visual Studio .net 2003

■代码

 1        SqlCommand SqlComm = new SqlCommand();
 2            try
 3            {
 4                SqlComm.Connection = sqlConn;
 5                SqlComm.CommandText = p_ProcedureName;
 6                SqlComm.CommandType=CommandType.StoredProcedure ;
 7                SqlComm.ExecuteNonQuery();
 8            }
 9            catch (SqlException myException)
10            {
11            for (int i=0; i < myException.Errors.Count; i++)
12            {
13                errorMessages = "Index #" + i + "\n" +
14                    "Source: " + myException.Errors[i].Source + "\n" +
15                    "Number: " + myException.Errors[i].Number.ToString() + "\n" +
16                    "State: " + myException.Errors[i].State.ToString() + "\n" +
17                    "Class: " + myException.Errors[i].Class.ToString() + "\n" +
18                    "Server: " + myException.Errors[i].Server + "\n" +
19                    "Message: " + myException.Errors[i].Message + "\n" +
20                    "Procedure: " + myException.Errors[i].Procedure + "\n" +
21                    "LineNumber: " + myException.Errors[i].LineNumber.ToString();
22            }
23            }
24


■说明
执行存储过程p_ProcedureName的过程中,截取到SqlException异常,以上内容如下:

ERROR: Index #0
Source: .Net SqlClient Data Provider
Number: -2
State: 0
Class: 10
Server: DatabaseServer
Message: Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding.
Procedure: ConnectionRead (WrapperRead()).
LineNumber: 0

究竟原因为何,最终未能调查出来。
最后换了另一种处理方式,将存储过程放到job中执行。然后代码中通过执行存储过程sp_start_job来启动作业,间接执行自定义的存储过程。避免发生该异常。
如果有更好的方法解决该问题,还请赐教!先行谢过!

 1                //执行启动作业的存储过程
 2                SqlParameter[] spParams = {
 3                                              new SqlParameter("@job_name",SqlDbType.NVarChar,128)
 4                                          }
;
 5 
 6                //作业名称
 7                spParams[0].Value = p_ProcedureName;
 8
 9                SqlCommand objSqlCommand = new SqlCommand();
10                objSqlCommand.Connection=objSqlConnection;
11                objSqlCommand.CommandType=CommandType.StoredProcedure;
12                objSqlCommand.CommandText="sp_start_job";
13                for(int i=0 ;i<spParams.Length;i++)
14                {
15                    objSqlCommand.Parameters.Add(spParams[i]);
16                }

17
18                objSqlCommand.ExecuteNonQuery();


 

posted on 2006-04-11 17:02  半空  阅读(2018)  评论(2编辑  收藏  举报