I am trying to bulk insert a local file into a remote MS_SQL database using pyodbc. I am able to connect to the DB and I am able to INSERT INTO
tables, as I have done it before. Where I have been having issues is to BULK INSERT
.
I am using BULK INSERT
as a way to speed up my INSERT
process.
The code looks like this:
statement = """ BULK INSERT BulkTable FROM 'C:\Users\userName\Desktop\Folder\Book1.csv' WITH (
FIRSTROW=2,
FIELDTERMINATOR=',',
ROWTERMINATOR = '\n'
);
"""
cursor.execute(statement)
cnxn.commit()
This code yields this error:
Traceback (most recent call last):
File "tester.py", line 41, in <module> cursor.execute(statement)
pyodbc.ProgrammingError:
('42000', '[42000] [Microsoft][SQL Server Native Client 11.0][SQL Server] Cannot bulk load because the file "C:\Users\userName\Desktop
\Folder\Book1.csv" could not be opened.
Operating system error code 3(The system cannot find the path specified.). (4861) (SQLExecDirectW)')`
I really don't understand why it can't open the file as the path is definitely correct.
Let me know if you need any more information.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…