I am trying to do a Bulk Insert statement using a pass-through query. I have the following code:
sSQL = "BULK INSERT tbl_Name "
sSQL = sSQL & "FROM 'C:\Users\UserName\Desktop\File.txt' "
sSQL = sSQL & "WITH "
sSQL = sSQL & "("
sSQL = sSQL & "FIELDTERMINATOR = ',', "
sSQL = sSQL & "ROWTERMINATOR='\n'"
sSQL = sSQL & ");"
Set db = CurrentDb
Set qdf = db.CreateQueryDef("")
qdf.Connect = db.TableDefs("dbo_tbl_Name").Connect
qdf.ReturnRecords = False
qdf.SQL = sSQL
qdf.Execute dbFailOnError
Set qdf = Nothing
Set db = Nothing
The error I get is: 3146
with a description of ODBC--call failed.
If I change the sSQL statement to a INSERT STATEMENT or a SELECT statement, the query executes just fine.
Why does my BULK INSERT not work in the PASS through query? I print out my sSQL string to make sure it is correct, and it seems to be:
BULK INSERT tbl_Name FROM 'C:\Users\UserName\Desktop\File.txt' WITH (FIELDTERMINATOR=',', ROWTERMINATOR='\n');
I have figured out the answer to this problem. Apparently there is a time out setting for ODBC connections. By adding the code qdf.ODBCTimeout = 900 '15 Min
the bulk insert was able to complete.
Thanks for everyone's time in this!