简体   繁体   English

来自Azure存储的Azure SQL批量插入

[英]Azure SQL Bulk Insert from Azure Storage

I am trying to test the bulk insert using OPENRECORDSET command in Azure SQL with no success. 我试图在Azure SQL中使用OPENRECORDSET命令测试批量插入,但没有成功。

Destination Table...eventually 目标表...最终

CREATE TABLE [dbo].[BCPTestTable](
  [Id] [int] IDENTITY(1,1) NOT NULL,
  [TextField] [varchar](500) NULL,
  [IntFIeld] [int] NULL,
  [DateField] [date] NULL,
  [DateTimeField] [datetime] NULL,
  [i18nTextField] [nvarchar](500) NULL,
  [BitField] [bit] NULL,
  [TInyIntField] [tinyint] NULL,
CONSTRAINT [PK_IX_BCPTestTable] PRIMARY KEY CLUSTERED 
(
  [Id] ASC
) WITH (STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]

Data File 资料档案

1   Jason   5   3/1/2018    3/1/2018 09:30:00   Test    1   50
2   Cindy   10  3/2/2018    3/2/2018 10:30:00   Testing 0   50

Format File 格式化文件

<?xml version="1.0"?>
<BCPFORMAT xmlns="http://schemas.microsoft.com/sqlserver/2004/bulkload/format" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <RECORD>
    <FIELD ID="1" xsi:type="CharFixed" LENGTH="12"/>
    <FIELD ID="2" xsi:type="CharFixed" LENGTH="500" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
    <FIELD ID="3" xsi:type="CharFixed" LENGTH="12"/>
    <FIELD ID="4" xsi:type="CharFixed" LENGTH="11"/>
    <FIELD ID="5" xsi:type="CharFixed" LENGTH="24"/>
    <FIELD ID="6" xsi:type="CharFixed" LENGTH="1000" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
    <FIELD ID="7" xsi:type="CharFixed" LENGTH="1"/>
    <FIELD ID="8" xsi:type="CharTerm" TERMINATOR="\r\n" MAX_LENGTH="5"/
  </RECORD>
  <ROW>
    <COLUMN SOURCE="1" NAME="Id" xsi:type="SQLINT"/>
    <COLUMN SOURCE="2" NAME="TextField" xsi:type="SQLVARYCHAR"/>
    <COLUMN SOURCE="3" NAME="IntFIeld" xsi:type="SQLINT"/>
    <COLUMN SOURCE="4" NAME="DateField" xsi:type="SQLDATE"/>
    <COLUMN SOURCE="5" NAME="DateTimeField" xsi:type="SQLDATETIME"/>
    <COLUMN SOURCE="6" NAME="i18nTextField" xsi:type="SQLNVARCHAR"/>
    <COLUMN SOURCE="7" NAME="BitField" xsi:type="SQLBIT"/>
    <COLUMN SOURCE="8" NAME="TInyIntField" xsi:type="SQLTINYINT"/>
  </ROW>
</BCPFORMAT>

For now, I'm just trying to select the data using the following query: 现在,我只是尝试使用以下查询选择数据:

SELECT  ID,
        TextField,
        IntField,
        DateField,
        DateTimeField,
        i18nTextField,
        BitField,
        TInyIntField
FROM    OPENROWSET(
            BULK 'test\TestData.txt', 
            DATA_SOURCE = 'xyzstorage',
            FORMATFILE = 'test\BCPTestTableFormat.txt', 
            FORMATFILE_DATA_SOURCE = 'xyzstorage'
        ) as Data

Previous to this, I did create a database scoped credential as well as a external data source which appears to be working. 在此之前,我确实创建了一个数据库范围的凭证以及一个似乎有效的外部数据源。

When I run the above SQL, I get the following error: 当我运行上述SQL时,出现以下错误:

Msg 4862, Level 16, State 1, Line 1 Cannot bulk load because the file "test\\BCPTestTableFormat.txt" is incomplete or could not be read. 消息4862,级别16,状态1,行1无法批量加载,因为文件“ test \\ BCPTestTableFormat.txt”不完整或无法读取。 Operating system error code 38(Reached the end of the file.). 操作系统错误代码38(到达文件末尾。)。

I have tried format files using both the XML version and original version both of which where generated using the latest (v14) BCP command. 我尝试使用XML版本和原始版本来格式化文件,这两个文件都是使用最新(v14)BCP命令生成的。 In both cases, I get the same error. 在两种情况下,我都会遇到相同的错误。

Random stuff I've tried: 我尝试过的随机内容:

  1. Change file name extensions (dumb but worth a shot) 更改文件扩展名(笨拙但值得一试)
  2. Made sure both versions of the format file had a blank line at the end. 确保格式文件的两个版本末尾都有空白行。
  3. Changed the direction of the slashed (doesn't find file if the other way) 更改了斜线的方向(反之则找不到文件)

Please help! 请帮忙!

Most likely there were characters added to the xml file such as spaces, or lines etc... Could use notepad ++ or a code editor, edit the sql /xml files then save and retry ? 最有可能是在xml文件中添加了字符,例如空格或行等。可以使用记事本++或代码编辑器,编辑sql / xml文件,然后保存并重试吗? this might resolve your issue. 这可能会解决您的问题。 This is a similar error message and similar resolution : https://www.sqlservercentral.com/Forums/Topic1490738-3077-1.aspx 这是类似的错误消息和类似的解决方法: https : //www.sqlservercentral.com/Forums/Topic1490738-3077-1.aspx

Based upon the information made available in your post, there is a missing closing angle bracket on line 11: 根据您发布的信息,第11行缺少一个闭合的尖括号:

 <?xml version="1.0"?> <BCPFORMAT xmlns="http://schemas.microsoft.com/sqlserver/2004/bulkload/format" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <RECORD> <FIELD ID="1" xsi:type="CharFixed" LENGTH="12"/> <FIELD ID="2" xsi:type="CharFixed" LENGTH="500" COLLATION="SQL_Latin1_General_CP1_CI_AS"/> <FIELD ID="3" xsi:type="CharFixed" LENGTH="12"/> <FIELD ID="4" xsi:type="CharFixed" LENGTH="11"/> <FIELD ID="5" xsi:type="CharFixed" LENGTH="24"/> <FIELD ID="6" xsi:type="CharFixed" LENGTH="1000" COLLATION="SQL_Latin1_General_CP1_CI_AS"/> <FIELD ID="7" xsi:type="CharFixed" LENGTH="1"/> <FIELD ID="8" xsi:type="CharTerm" TERMINATOR="\\r\\n" MAX_LENGTH="5"/ </RECORD> 

在此处输入图片说明

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

相关问题 将 CSV 文件从 Azure blob 存储批量插入到 SQL 托管实例 - Bulk insert CSV file from Azure blob storage to SQL managed instance 从 blob 存储失败的 Azure SQL 批量插入:未找到引用的外部数据源“MyAzureBlobStorage” - Azure SQL bulk insert from blob storage failure: Referenced external data source "MyAzureBlobStorage" not found 有没有办法从本地 Azure Blob 存储批量插入? - Is there a way BULK INSERT from local Azure Blob Storage? 使用其他语言从 Azure Blob 存储批量插入 - Bulk insert from Azure Blob Storage with other language 将 json 从 Azure Blob 存储批量上传到 Azure SQL db 时出错 - Error when bulk uploading json to Azure SQL db from Azure Blob Storage 将数据从 Azure Synapse Serverless SQL 池批量加载到 Azure 存储或 Databricks Spark 的最佳方法 - Best way to bulk load data from Azure Synapse Serverless SQL pools into Azure storage or Databricks Spark 批量插入在Azure SQL Server中无法正常工作 - Bulk insert is not working properly in Azure SQL Server Azure SQL Server 中大容量插入的权限问题 - Permission Issue on Bulk Insert in Azure SQL Server Azure SQL Server中的批量插入或BCP - Bulk Insert or BCP in Azure SQL Server 批量插入Azure SQL且SQLAlchemy不持久 - Bulk insert into Azure SQL with SQLAlchemy not persisting
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM