日期:2014-05-17  浏览次数:20858 次

求SQL执行与程序执行效率分析
版本sql2008,写了一个存储过程,语句相当复杂,用于很多临时表将结果集中起来.

我直接在sql查询分析里执行:EXEC 存储过程名字 '201302','20130116','20130219','Y'  (执行时间大约27秒可以完成)


同样,我用vs2008,.net2.0编译的程序,执行如下方法,只看"断点位置"时间,超过5分钟都不出结果,看任务样进程时,程序未响应.

public DataSet GetDataSet(string strSql, CommandType cmdType, params SqlParameter[] param)
        {
            using (SqlConnection con = new SqlConnection(connectionStr))
            {
                SqlDataAdapter sda = null;
                try
                {
                    con.Open();
                    SqlCommand com = new SqlCommand(strSql, con);//strSql参数为:EXEC 存储过程名字 '201302','20130116','20130219','Y'  
                    com.CommandTimeout = 0;   
                       com.CommandType = cmdType;
                    com.Parameters.AddRange(param);
                    sda = new SqlDataAdapter(com);
                    DataSet ds = new DataSet();
                    sda.Fill(ds,"myDs");//断点位置
                    return ds;
                }
                catch (SqlException ex)
                {
                    throw new Exception("SQL数据库连接失败,执行DataSet查询产生错误: " + ex.Message);
                }
                finally
                {
                    sda.Dispose();
                    con.Close();
                }
           &nbs