2012-11-22 55 views
2

先生, 我正在使用vb6.0和sql server 2005.我寫了一個小程序,它在sql server中返回直接結果,但在vb 6.0中它返回超時。任何想法的任何身體?請幫忙?Visual Basic 6.0 + Sql Server存儲過程超時問題

我的程序:

Alter procedure 
[dbo].[SpRptSalesDayBookSummary](@liComid integer,@liPerid integer,@ad_dtfrm DateTime,@ad_dtto DateTime) 
AS 
begin 
SET NOCOUNT ON; 
Select SaleDate,Sum(Grand) as tot 
from SalesMaster a,SalesDet b 
Where a.id=b.RefId 
    And a.CompanyId= @liComid 
    And [email protected] 
    And a.SaleDate Between @ad_dtfrm And @ad_dtto 
Group By SaleDate Order By SaleDate 
End 

我的VB代碼:

Dim cmd As New ADODB.Command 
    Dim rs1 As New ADODB.Recordset 
    Dim param2 As ADODB.Parameter 
    Dim param3 As ADODB.Parameter 
    Dim param4 As ADODB.Parameter 
    Dim param5 As ADODB.Parameter 

    g_objData.DBConn.CursorLocation = adUseClient 
    Set cmd.ActiveConnection = g_objData.DBConn 
    cmd.CommandType = adCmdStoredProc 
    cmd.CommandText = "SpRptSalesDayBookSummary" 
    Set param2 = cmd.CreateParameter("Input", adInteger, adParamInput) 
    cmd.Parameters.Append param2 
    param2.value = 20 
    Set param3 = cmd.CreateParameter("Input", adInteger, adParamInput) 
    cmd.Parameters.Append param3 
    param3.value = 8 
    Set param4 = cmd.CreateParameter("Input", adDate, adParamInput) 
    cmd.Parameters.Append param4 
    param4.value = Format(PD_DtFrm, "yyyy-mm-dd") 
    Set param5 = cmd.CreateParameter("Input", adDate, adParamInput) 
    cmd.Parameters.Append param5 
    param5.value = Format(PD_DtTo, "yyyy-mm-dd") 

    Set rs1 = cmd.Execute 

請幫助。

+0

你確定你沒有鎖定SQL嗎? (使用sp_who來找出)。 – rufo

+0

看起來好像在將參數添加到命令對象後將值設置爲參數。嘗試先設置值爲param(param.value = 20等),然後將其添加到命令對象。 – Sridhar

回答

0

您不說什麼.CommandTimeout屬性是針對Connection對象的,但您可能需要將其關閉。我相信你也可以在命令對象中指定.CommandTimeout屬性 - 嘗試將它設置爲600(10分鐘)。

我看過之前的代碼,在幾秒鐘內將CommandTimeout屬性設置爲針對連接,認爲這是分鐘!