adodb执行sql命令超时

时间:2019-04-18 21:32:09

标签: sql excel vba adodb

我下面有这段代码,它挂在我身上。它可以很好地处理几个文件...但是它现在挂在我身上,并因错误而超时(-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;")

1 个答案:

答案 0 :(得分:0)

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

谢谢! zedfoxus。