问题
I have this code below and it is hanging on me. It worked fine for several files...but it is now hanging on me and times out with error (-2147217871:Query timeout expired).
'This is what it looks like in SQL Server when I print the string in the immediate window:
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 code below that builds the sql string:
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:
I had a query open with that table in sql studio...that's why it could not do this insert. I closed that query and it worked fine after.
Thanks! zedfoxus.
来源:https://stackoverflow.com/questions/55753980/adodb-execute-sql-command-timeout