[英]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: 我尝试过的随机内容:
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.