简体   繁体   English

在 SSMS 中使用存储过程时使用批量插入到 Azure SQL DB 时出错

[英]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.我正在尝试将本地 CSV 文件中的数据导入 Azure 数据库。 the idea is to allow the customer to do bulk inserts into the system using a preformatted CSV file.这个想法是允许客户使用预先格式化的 CSV 文件向系统进行批量插入。

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.消息 4861,级别 16,状态 1,第 1 行无法批量加载,因为无法打开文件“C:\\ImportFrom\\ImportData.csv”。 Operating system error code (null).操作系统错误代码(空)。

How do I resolve this issue?我该如何解决这个问题?

You can't use bulk insert in Azure SQL DB with file name, because it should be on the SQL Server machine.不能在 Azure SQL DB 中使用文件名bulk insert ,因为它应该在 SQL Server 计算机上。

You can use however BCP utility executed on your computer, to bulk copy this file to Azure SQL:但是,您可以使用在您的计算机上执行的BCP实用程序将此文件批量复制到 Azure SQL:

bcp database.dbo.table in C:\ImportFrom\ImportData.csv
    -S yourserver.database.windows.net
    -U someusername -P strongpassword

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM