OLE DB "BULK", How to spot where is happening? - sql-server

I am doing a bulk operation on sql server 2008 and I get the OLE DB "BULK" error. I know that it is because my table does not have a column that the file has or vice versa.
Despite knowing what is happening this do not help me a lot. How can I get the exact line of the bulk that is failing? Or any other hint to try to solve the error quickly.
Thank you.

Try this :
BULK INSERT [table_name]
FROM 'C:\...\...\[filename].csv' -- -- This is server path not local
WITH (
FIELDTERMINATOR = ',',
ROWTERMINATOR = '\n',
ERRORFILE = 'C:\...\...\[logfilename].log'
);

Related

Bulk Insert SQL Server FROM network file

Can't seem to get this bulk insert to work. I know the SQL Server windows account has appropriate permissions to this network folder - that has been verified.
The error I get is: Msg 12704, Level 16, State 1, Line 1 Bad or inaccessible location specified in external data source "(null)".
I can copy and paste the path into my windows finder and it opens the file but maybe I am using the wrong syntax in the SQL statement?
Here is the SQL statement:
BULK INSERT Employee_be.dbo.Table_Cur_Test
FROM '\\SERVERPATH\Data\Test\CurTest.txt'
WITH
(
FIELDTERMINATOR = ',',
ROWTERMINATOR = ';\n'
)
GO
Any suggestions?

SQL Server SSMS Bulk Insert Access denied

I'm trying to use the following codes to do some bulk insert:
BULK INSERT [xxx].[xxx].[xxx]
FROM 'E:\xxx\xxx.csv'
WITH (
FIRSTROW = 2,
FIELDTERMINATOR = ',', --CSV field delimiter
ROWTERMINATOR = '\n', --Use to shift the control to next row
TABLOCK
)
But it reports an error:
Cannot bulk load because the file "E:\xxx\xxx.csv" could not be opened. Operating system error code (null).
Some posts show it's because my SSMS 2017 uses some sort of dummy account which doesn't have the permission to access the file on the shared drive.
I've tried running SSMS 2017 as admin, but it didn't work.
My question is how to create a domain account for SSMS 2017, so it can bulk insert? (a step-by-step guide is preferred).

("IID_IColumnsInfo") error with SQL Server BULK INSERT of CSV file

I'm new to SQL Server, so forgive me for being a bit of a noob here.
The code shown here returns the following error:
Cannot obtain the required interface ("IID_IColumnsInfo") from OLE DB provider "BULK" for linked server "(null)".
Code:
BULK INSERT testingtable
FROM 'D:\TimeLords\data\db-test-file.csv'
WITH
(FORMAT = 'CSV',
FIELDQUOTE = '"',
FIRSTROW = 2,
FIELDTERMINATOR = ',',
ROWTERMINATOR = '\n',
TABLOCK)
I've tried using:
ROWTERMINATOR = '0x0a'
and
ROWTERMINATOR = '\r\n'
This is the CSV file: https://gyazo.com/0392b660c97e3cac27f2337993190c69
This is my SQL table: https://gyazo.com/fbbaf6204df9bb574d8887864cc95ea0
And this is the complete SQL query: https://gyazo.com/ffe020437f07524ce44420bedeebf0d4
I've scouted StackOverflow and can't find any solution which works. Any ideas would be appreciated.
Thanks
There's another potential culprit. I've been running BULK INSERTs into my SQL Server 2017 Express, and my syntax used FORMAT = 'CSV' and a ROWTERMINATOR of '\n' -- and it had been working fine for months.
I added a new column to the other system where I was routinely exporting data as a CSV, and when I went to do another BULK INSERT, it was failing because I had an extra column in my CSV that didn't line up with the columns in my SQL table. DOH! I just needed to add that same new column in my SQL db and all was well again. A stupid error on my part, but maybe it will help someone else.
Change FORMAT = 'CSV' to DATAFILETYPE = 'char'
or just remove the FORMAT = 'CSV' line as your file may not be RFC 4180 compliant.
BULK INSERT testingtable
FROM 'D:\TimeLords\data\db-test-file.csv'
WITH
(FIELDQUOTE = '"',
FIRSTROW = 2,
FIELDTERMINATOR = ',',
ROWTERMINATOR = '\n',
TABLOCK)
this has worked for me with this error.
Old post, but hey, every bit of knowledge helps. You can also run into this issue if you use a CSV other encoding or types, e.g. if you save CSV for Macintosh or UTF-8 (as you can in Excel), this is not compliant with FORMAT = 'CSV'. You can try other options like row terminator = '\r' while removing FORMAT = 'CSV' that did it for me for non-windows-based CSV files.
For me the error was an extra space on the end of the first row.

Import text file to SQL Server using Bulk Insert

This is my sql
BULK INSERT dbo.Account FROM 'G:\Import\Account3.txt'
WITH
(
FIELDTERMINATOR = '" | "'
)
GO
When I run the sql i got this error
Msg 4866, Level 16, State 1, Line 1
The bulk load failed.
The column is too long in the data file for row 1, column 1. Verify that the field terminator and row terminator are specified correctly.
Msg 7399, Level 16, State 1, Line 1
The OLE DB provider "BULK" for linked server "(null)" reported an error. The provider did not give any information about the error.
Msg 7330, Level 16, State 2, Line 1
Cannot fetch a row from OLE DB provider "BULK" for linked server "(null)".
Please help me. I already tried many ways but still get the same error.
From your example SQL, it seems you are missing a ROWTERMINATOR statement, specifying how rows are to be differentiated from one another.
Your query would then become something like
BULK INSERT dbo.Account FROM 'G:\Import\Account3.txt'
WITH
(
FIELDTERMINATOR = '" | "',
ROWTERMINATOR = '\r\n'
)
GO
Try this
BULK
INSERT dbo.Account
FROM 'G:\Import\Account3.txt'
WITH
(
FIELDTERMINATOR = '|',
ROWTERMINATOR = '\n'
)
GO

Bulk Upload: "unexpected end of file" on new server

I am trying to do a bulk upload in one table in our sql database. This query was running good before, when we had the database on different server, but now on the new server I am getting an error.
Here is all I have:
sql bulk import query:
BULK
INSERT NewProducts
FROM 'c:\newproducts.csv'
WITH
(
FIELDTERMINATOR = ',',
ROWTERMINATOR = '\n'
)
GO
And the errors I am getting are:
Msg 4832, Level 16, State 1, Line 1
Bulk load: An unexpected end of file was encountered in the data file.
Msg 7399, Level 16, State 1, Line 1
The OLE DB provider "BULK" for linked server "(null)" reported an error. The provider did not give any information about the error.
Msg 7330, Level 16, State 2, Line 1
Cannot fetch a row from OLE DB provider "BULK" for linked server "(null)".
Thanks for any help in advance.
For anybody else who comes across this question looking for an answer, this error also happens when the number of columns in your CSV file don't match the columns of the table you're doing the bulk insert into.
I've encountered this before and there are a few things to look for:
Make sure that your csv file doesn't have any blank rows at the top.
Make sure that there are no additional blank rows at the end of the file.
Make sure that the ROWTERMINATOR is actually \n and not \r\n
If you do all three of these and are still getting the error let me know.
In my case the file I was trying to access was in a directory that the SQL Sever process did not have access to. I moved my flat files to a directory SQL had access to and this error was resolved.

Resources