当前位置:编程学习 > C#/ASP.NET >>

C# web开发中,存储过程连接超时

如题,数据库连接正常,在(SqlDataAdapter.Fill()数据超时。但是在SQL Server中单独执行该存储过程,时间很快,整个查询结果不到1万行数据。就是在 C#中使用该存储过程超时, 该存储过程是查询语句,使用了Left Join 。请大侠们指点。谢谢! --------------------编程问答--------------------
        /// <summary>
        /// 执行存储过程,返回SqlDataReader ( 注意:调用该方法后,一定要对SqlDataReader进行Close )
        /// </summary>
        /// <param name="storedProcName">存储过程名</param>
        /// <param name="parameters">存储过程参数</param>
        /// <returns>SqlDataReader</returns>
        public static SqlDataReader RunProcedure(string storedProcName, IDataParameter[] parameters)
        {
            SqlConnection connection = new SqlConnection(connectionString);
            SqlDataReader returnReader;
            connection.Open();
            SqlCommand command = BuildQueryCommand(connection, storedProcName, parameters);
            command.CommandType = CommandType.StoredProcedure;
            returnReader = command.ExecuteReader(CommandBehavior.CloseConnection);
            return returnReader;

        } --------------------编程问答-------------------- CREATE PROCEDURE [dbo].[PRO_S_SQAStoreRoom]
@PanelSN Varchar(250),
@PanelSource Varchar(250),
@SupplierName Varchar(250),
@StoreRoomSign Varchar(250),
@PanelCategory Varchar(250),
@StoreString Varchar(250),
@NextString Varchar(250),
@JudgeString Varchar(250),
@JudgeCategoryString Varchar(250),
@bTime Varchar(50),
@eTime Varchar(50)
AS

Select *  from 
(
Select [PanelInfo].[PanelId],[PanelInfo].[PanelSN],[PanelInfo].[NewPanelSN],[PanelInfo].[StoreRoomSign],
   [PanelInfo].[SupplierType],[PanelInfo].[PanelCategory],
   [PanelSource],[SupplierName],[SQALast].[SQAStoreRoomTime],
Case isnull(@PanelSN,'0000') 
----------------------SN传入NULL时
when '0000' then 
Case [ReplaceState] 
when '1' then [NewPanelSN]
ELSE [PanelSN]
End
----------------------模糊查询SN时
ELSE
Case 
when [NewPanelSN] Like '%' + @PanelSN+ '%' then [NewPanelSN] 
when [PanelSN] Like '%' + @PanelSN + '%' then [PanelSN]
End
End
 as [ResultSN],
----------------------SN标识
Case [PanelCategory]
when 'ACER' then [StoreRoomSign]+',ACER'
ELSE [StoreRoomSign]
END
as [PanelCategoryString],
----------------------库存状态
Case [SQAStoreRoomState]
when '0' then '已出库'
when '1' then '库存中'
ELSE 'UnKonw'
END
as [StoreString],
----------------------SQA判定状态
Case [SQAStoreRoomState]
when '0' then '已出库'
when '1' then 
Case [SQAJudgeResult]
when '0' then '未判定'
when '2' then '送外维修'
when '3' then 'NG'
when '4' then 'OK'
when '5' then '报废'
when '41' then '保内'
when '42' then '保内自损'
when '43' then '保外'
when '44' then '保外自损'
ELSE 'UnKonw'
END
ELSE 'UnKonw'
END
as [JudgeString],
----------------------SQA判定类别
Case [SQAStoreRoomState]
when '0' then '已出库'
when '1' then 
Case [SQAStoreRoomPhase]
when '3' then '维修判'
when '5' then 'RMA判'
when '4' then '厂商判'
when '0' then 
Case [SQACheck].[SQAJudgeCount]
when 1 then '坏品判'
ELSE '送外判'
End
ELSE 'UnKonw'
END
ELSE 'UnKonw'
END
as [JudgeCategoryString],
----------------------流向
Case [SQAStoreRoomState]
when '0' then '已出库'
when '1' then 
Case [PanelInfo].[CurrentState]
when '2' then 'SQA判定'
when '10' then '坏品库'
when '11' then '坏品库'
when '12' then '好品库'
when '13' then '报废库'
when '16' then 'SQA判定'
when '18' then 'SQA判定'
when '19' then 'RMA Panel'
when '23' then 'RMA Panel'
when '30' then 'ACER库'
when '41' then '厂商复判'
when '42' then  
Case [PanelCategory]
when 'ACER' then 'ACER库'
ELSE '坏品库'
END
when '43' then  
Case [PanelCategory]
when 'ACER' then 'ACER库'
ELSE '坏品库'
END
when '44' then  
Case [PanelCategory]
when 'ACER' then 'ACER库'
ELSE '坏品库'
END
ELSE 'UnKonw'
END
ELSE 'UnKonw'
END
as [NextString]
from 
( Select * from [SQAStoreRoom] Where [SQAStoreRoomId] in
(Select max([SQAStoreRoomId]) from [SQAStoreRoom] where [SQAStoreRoomTime]>=@bTime and [SQAStoreRoomTime]<=@eTime Group By [PanelId])
)[SQALast]
Left join [PanelInfo]
on [PanelInfo].[PanelId]=[SQALast].[PanelId]
Left join
(Select Count(*)as [SQAJudgeCount],[PanelId] from [SQAStoreRoom]  Group by [PanelId])[SQACheck]
on [SQACheck].[PanelId]=[PanelInfo].[PanelId]
)[SQASelect]
Where 1=1 
and ([SQAStoreRoomTime]>=@bTime and [SQAStoreRoomTime]<=@eTime)
and (@PanelSN is null or [PanelSN] Like '%' + @PanelSN + '%' or [NewPanelSN] Like '%' + @PanelSN+ '%' )
and (@PanelSource is null or [PanelSource] = @PanelSource)
and (@SupplierName is null or [SupplierName] = @SupplierName)
and (@StoreRoomSign is null or [StoreRoomSign] = @StoreRoomSign)
and (@PanelCategory is null or [PanelCategory] = @PanelCategory)
and (@StoreString is null or [StoreString] = @StoreString)
and (@NextString is null or [NextString] = @NextString)
and (@JudgeString is null or [JudgeString] = @JudgeString)
and (@JudgeCategoryString is null or [JudgeCategoryString] = @JudgeCategoryString)
order by [SQAStoreRoomTime] --------------------编程问答--------------------  /// 执行存储过程
        /// </summary>
        /// <param name="storedProcName">存储过程名</param>
        /// <param name="parameters">存储过程参数</param>
        /// <param name="tableName">DataSet结果中的表名</param>
        /// <returns>DataSet</returns>
        public static DataSet RunProcedure(string storedProcName, IDataParameter[] parameters, string tableName)
        {
            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                DataSet dataSet = new DataSet();
                connection.Open();
                SqlDataAdapter sqlDA = new SqlDataAdapter();
                sqlDA.SelectCommand = BuildQueryCommand(connection, storedProcName, parameters);
                sqlDA.Fill(dataSet, tableName);
                connection.Close();
                return dataSet;

            }

        } --------------------编程问答-------------------- 优化存储过程 --------------------编程问答-------------------- 存储过程 单独执行 不用1S ,不明白该怎么优化,能说具体点吗?
补充:.NET技术 ,  C#
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,