adodb执行sql命令超时

Posted

技术标签:

【中文标题】adodb执行sql命令超时【英文标题】:adodb execute sql command timeout 【发布时间】:2019-04-18 21:32:09 【问题描述】:

我在下面有这段代码,它挂在我身上。它适用于几个文件......但它现在挂在我身上并且超时并出现错误(-2147217871:查询超时已过期)。

'这是我在即时窗口中打印字符串时在 SQL Server 中的样子:

BEGIN TRAN; 
INSERT INTO [dbo].[XLSHdr] WITH(TABLOCK) ([HdrID],[TabName],[FileHyperLink],[FileName],[DocumentType],[EmailID],[Subject],[SentDate],[AttachmentName],[TextFileLink],[DateReceived],[Vendor],[ContactName],[ContactNumber],[SupplierName],[VendorNum],[Increase],[Decline],[EDLP],[Rollbk],[Prepaid],[Collect],[CostKeyed],[RetailKeyed],[Fixed],[Variable],[BuyerComments],[PriorMktPrice],[CurrentMktPrice],[BellyMktUsed],[MktDate],[Perc_Chg],[Cost_EffDate],[Cost_EndDate],[Retail_EffDate],[Retail_EndDate],[SubmittedDate],[aTitle],[bTitle],[cTitle],[dTitle],[COOP],[TypeOfChange],[InTransit],[WHSE],[Store],[WeeksInvOwned] ) 
VALUES ('34454','RDC & DSD Cost Change Form','\\amer.prgx.com\auditfiles\WalMart-US\Public\MTX\Rollback\D\DFDD-1718\Hormel Pepperoni Price Increase Effective August 2 2017 (2).xlsx','Hormel Pepperoni Price Increase Effective August 2 2017 (2).xlsx','Promo','DFDDC3A1202C3E1AF7332F1BB4BEAC00FA09498320170822191718','Hormel Pepperoni Price Increase Effective August 2 2017 (2).xlsx','8/22/2017 3:17:18 PM','Hormel Pepperoni Price Increase Effective August 2 2017 (2).xlsx','\\amer.prgx.com\auditfiles\WalMart-US\Public\MTX\Rollback\D\DFDD-1718\Hormel Pepperoni Price Increase Effective August 2 2017 (2)_met.txt','','','','','','','','','','','','','','','','','','','','','','','08/02/17','','08/02/17','','','WAL-MART COST CHANGE FORM','','','','','','','','','')
COMMIT TRAN;

下面的 vba 代码构建 sql 字符串:

 Dim ConUpd As Object
 Set ConUpd = CreateObject("ADODB.Connection")
    strConn = GetConnectionString()
    ConUpd.Open strConn
    ConUpd.CommandTimeout = 60

 SQL = "INSERT INTO [dbo].[XLSHdr] WITH(TABLOCK) "
        SQL = SQL & "([HdrID],[TabName],[FileHyperLink],[FileName],[DocumentType]"
        SQL = SQL & ",[EmailID],[Subject],[SentDate],[AttachmentName],[TextFileLink],[DateReceived],[Vendor]"
        SQL = SQL & ",[ContactName],[ContactNumber]"
        SQL = SQL & ",[SupplierName],[VendorNum],[Increase],[Decline]"
        SQL = SQL & ",[EDLP],[Rollbk],[Prepaid],[Collect],[CostKeyed]"
        SQL = SQL & ",[RetailKeyed],[Fixed],[Variable],[BuyerComments],[PriorMktPrice],[CurrentMktPrice]"
        SQL = SQL & ",[BellyMktUsed],[MktDate],[Perc_Chg],[Cost_EffDate],[Cost_EndDate],[Retail_EffDate],[Retail_EndDate],[SubmittedDate]"
        SQL = SQL & ",[aTitle],[bTitle],[cTitle],[dTitle],[COOP],[TypeOfChange],[InTransit],[WHSE],[Store],[WeeksInvOwned] )"

        SQL = SQL & " VALUES ('" & HdrID & "','" & Replace(TabName, "'", " ") & "','" & Replace(FileHyperLink, "'", "''") & "','" & Replace(FileName, "'", " ") & "','" & fReplaceToOne(Replace(DocumentType, "'", " ")) & "'"
        SQL = SQL & ",'" & fReplaceToOne(Replace(sTxtEmailID, "'", " ")) & "','" & Replace(sTxtSubject, "'", " ") & "','" & fReplaceToOne(Replace(sTxtDate, "'", " ")) & "','" & Replace(sTxtAttName, "'", " ") & "'"
        SQL = SQL & ",'" & Replace(sTxtFileLink, "'", " ") & "','" & fReplaceToOne(Replace(sDateReceived, "'", " ")) & "','" & fReplaceToOne(Replace(sTxtVendorName, "'", " ")) & "','" & fReplaceToOne(Replace(contactInfo, "'", " ")) & "'"
        SQL = SQL & ",'" & fReplaceToOne(Replace(contactInfo, "'", " ")) & "','" & fReplaceToOne(Replace(SupplierName, "'", " ")) & "','" & fReplaceToOne(Replace(VendorNum, "'", " ")) & "','" & fReplaceToOne(Replace(Increase, "'", " ")) & "'"
        SQL = SQL & ",'" & fReplaceToOne(Replace(Decline, "'", " ")) & "','" & fReplaceToOne(Replace(EDLP, "'", " ")) & "','" & fReplaceToOne(Replace(nRollback, "'", " ")) & "','" & fReplaceToOne(Replace(Prepaid, "'", " ")) & "','" & fReplaceToOne(Replace(Collect, "'", " ")) & "'"
        SQL = SQL & ",'" & fReplaceToOne(Replace(CostKeyed, "'", " ")) & "','" & fReplaceToOne(Replace(RetailKeyed, "'", " ")) & "','" & fReplaceToOne(Replace(nFixed, "'", " ")) & "','" & fReplaceToOne(Replace(wtVariable, "'", " ")) & "','" & fReplaceToOne(Replace(BuyerComments, "'", " ")) & "'"
        SQL = SQL & ",'" & fReplaceToOne(Replace(PriorMktPrice, "'", " ")) & "','" & fReplaceToOne(Replace(CurrentMktPrice, "'", " ")) & "','" & fReplaceToOne(Replace(BellyMktUsed, "'", " ")) & "','" & fReplaceToOne(Replace(MktDate, "'", " ")) & "','" & fReplaceToOne(Replace(PercChg, "'", " ")) & "'"
        SQL = SQL & ",'" & fReplaceToOne(Replace(hCostEffDate, "'", " ")) & "','" & fReplaceToOne(Replace(hCostEndDate, "'", " ")) & "','" & fReplaceToOne(Replace(hRetEffDate, "'", " ")) & "','" & fReplaceToOne(Replace(hRetEndDate, "'", " ")) & "','" & fReplaceToOne(Replace(SubmittedDate, "'", " ")) & "'"
        SQL = SQL & ",'" & Left(fReplaceToOne(Replace(aTitle, "'", " ")), 150) & "','" & Left(fReplaceToOne(Replace(bTitle, "'", " ")), 150) & "','" & Left(fReplaceToOne(Replace(cTitle, "'", " ")), 150) & "','" & Left(fReplaceToOne(Replace(dTitle, "'", " ")), 150) & "','" & Left(fReplaceToOne(Replace(COOPh, "'", " ")), 50) & "','" & Left(Replace(TypeOfChange, "'", " "), 100) & "'"
        SQL = SQL & ",'" & fReplaceToOne(Replace(inTransith, "'", " ")) & "','" & fReplaceToOne(Replace(WHSEh, "'", " ")) & "','" & fReplaceToOne(Replace(Storeh, "'", " ")) & "','" & fReplaceToOne(Replace(WeeksInvOwnedh, "'", " ")) & "')"

        Call ConUpd.Execute("BEGIN TRAN; " & vbCrLf & SQL & vbCrLf & " COMMIT TRAN;")

【问题讨论】:

只是超时了。你能把超时时间增加到一分钟以上吗? 您可以删除WITH(TABLOCK) 并尝试该查询吗? 【参考方案1】:

我在 sql studio 中打开了该表的查询...这就是它无法执行此插入的原因。我关闭了该查询,之后它运行良好。

谢谢!泽狐。

【讨论】:

以上是关于adodb执行sql命令超时的主要内容,如果未能解决你的问题,请参考以下文章

增加 SQL 命令的命令超时

处理 ClientInsertServerInsert 同步冲突时出现 SQL 命令“超时”异常

paramiko执行命令超时的问题

用于修复 .NET 应用程序以解决 SQL Server 超时问题并缩短执行时间的清单

在 Access 前端中为链接的 SQL 表/视图设置命令超时

shell 中给命令设置超时时间