Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error when using bulk insert into Azure SQL DB when using stored proc in SSMS

I am trying to importdata from a local CSV file into an Azure database. the idea is to allow the customer to do bulk inserts into the system using a preformatted CSV file.

The code I am using is:

    BULK INSERT tmp_Import_Truck
   FROM 'C:\ImportFrom\ImportData.csv'
   WITH
     (
        FIELDTERMINATOR =',',
        ROWTERMINATOR = '\n'
      )

The problem is that I am getting an eror that it cannot open the file.

Msg 4861, Level 16, State 1, Line 1 Cannot bulk load because the file "C:\ImportFrom\ImportData.csv" could not be opened. Operating system error code (null).

How do I resolve this issue?

like image 487
Marc L Avatar asked Jul 27 '26 20:07

Marc L


1 Answers

You can't use bulk insert in Azure SQL DB with file name, because it should be on the SQL Server machine.

You can use however BCP utility executed on your computer, to bulk copy this file to Azure SQL:

bcp database.dbo.table in C:\ImportFrom\ImportData.csv
    -S yourserver.database.windows.net
    -U someusername -P strongpassword
like image 175
Andrey Nikolov Avatar answered Jul 29 '26 12:07

Andrey Nikolov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!