批量插入的问题
我正在尝试将此链接中的数据插入到我的 SQL 服务器 https://www.ian.com/affiliatecenter/include/V2/CityCooperativesList.zip
我创建了表
CREATE TABLE [dbo].[tblCityCoordinatesList](
[RegionID] [int] NOT NULL,
[RegionName] [nvarchar](255) NULL,
[Coordinates] [nvarchar](4000) NULL
) ON [PRIMARY]
并且我正在运行以下脚本来执行批量插入
BULK INSERT tblCityCoordinatesList
FROM 'C:\data\CityCoordinatesList.txt'
WITH
(
FIRSTROW = 2,
MAXERRORS = 0,
FIELDTERMINATOR = '|',
ROWTERMINATOR = '\n'
)
但是批量插入失败并出现以下错误
Cannot obtain the required interface ("IID_IColumnsInfo") from OLE DB provider "BULK" for linked server "(null)".
当我谷歌时,我发现几篇文章说问题可能与 RowTerminator 有关,但我尝试了诸如此类的所有内容\n\r、\n 等,但没有任何效果。
有人可以帮我将此数据插入我的数据库吗?
I am trying to insert the data from this link to my SQL server
https://www.ian.com/affiliatecenter/include/V2/CityCoordinatesList.zip
I created the table
CREATE TABLE [dbo].[tblCityCoordinatesList](
[RegionID] [int] NOT NULL,
[RegionName] [nvarchar](255) NULL,
[Coordinates] [nvarchar](4000) NULL
) ON [PRIMARY]
And I am running the following script to do the bulk insert
BULK INSERT tblCityCoordinatesList
FROM 'C:\data\CityCoordinatesList.txt'
WITH
(
FIRSTROW = 2,
MAXERRORS = 0,
FIELDTERMINATOR = '|',
ROWTERMINATOR = '\n'
)
But the bulk insert fails with following error
Cannot obtain the required interface ("IID_IColumnsInfo") from OLE DB provider "BULK" for linked server "(null)".
When I google, I found several articles which says the issue may be with RowTerminator, but I tried everything like \n\r, \n etc, but nothing is working.
Could anyone please help me to insert this data into my database?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
尝试
ROWTERMINATOR = '0x0a'
。它应该有效。
Try
ROWTERMINATOR = '0x0a'
.it should work.
如果表和导入文件之间的列数不匹配,也会发生这种情况
This can also happen if the number of columns mismatch between the table and the imported file
当使用 FORMAT='CSV' 选项时,我在 SQL2019 上遇到了这个问题,并且源文件中每行的末尾都有一个逗号。因此,批量插入的表需要有一个额外的虚拟字段,以满足每个记录在源文件中本质上有一个空白字段的事实。
!
I had this on SQL2019 when the FORMAT='CSV' option was used, and there was a comma on the end of each line in the source file. So the table your BULK inserting into needed to have an extra dummy field to cater for the fact each record has essentially a blank field in the source file.
!
我收到了相同的错误消息,正如您所提到的,它与意外的行结束有关。
在我的例子中,行结尾在 fmt 文件中指定为 Windows 行结尾 (CRLF),写为
\r\n
,并且要处理的数据文件具有 Mac 经典行结尾 (CR)。我用一个可以显示当前行结尾并更改它的编辑器解决了这个问题。我使用 EditPad Lite 来显示打开的文件行以底部栏结尾,按下它允许替换为预期的文件行。
I got the same error message, and as you had mention, it was related to unexpected line ending.
In my case the line ending was specified in a fmt file as a Windows Line ending (CRLF), written as
\r\n
, and the data file to process has a Mac classic one (CR).I solved it with an editor that can show the current line ending and change it. I used EditPad Lite wich shows the opened file line ending in the bottom bar and pressing it allow to replace with the expected one.
我得到同样的错误,可能是由于文件编码问题。我通过使用 Notepad++ 打开有问题的 CSV 文件、选择所有内容并复制到剪贴板来修复此问题。接下来,创建一个新的文本文件(确保其具有 CSV 文件扩展名),使用 Notepad++ 打开它,然后将文本粘贴到新文件中。保存并关闭所有文件。您应该能够成功地将新的 CSV 文件加载到 SQL 服务器中。
I get the same error, probably from the file encoding problem. I fixed it by opening the problem CSV file using Notepad++, select everything and copy to clipboard. Next, create a new text file (making sure it has the CSV file extension), open it using Notepad++, then paste the text to the new file. Save and close all files. You should be able to successfully load the new CSV file into the SQL server.
您需要从 Windows 登录(而不是从 SQL)运行 BULK INSERT - 命令。现在我没有任何例子
you need run BULK INSERT - command from windows login (not from SQL). Now I don't have any examples