SQL Sql批量插入——文件不存在
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10016799/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Sql Bulk Insert -- File does not exist
提问by Nate Pet
I have the following query to insert into a table
我有以下查询要插入到表中
BULK
INSERT tblMain
FROM 'c:\Type.txt'
WITH
(
FIELDTERMINATOR = ',',
ROWTERMINATOR = '\n'
)
GO
It get the message
它得到消息
Msg 4860, Level 16, State 1, Line 1
Cannot bulk load. The file "c:\Type.txt" does not exist.
消息 4860,级别 16,状态 1,第 1 行
无法批量加载。文件“c:\Type.txt”不存在。
The file is clearly there. Anything I may be overlooking?
该文件显然在那里。有什么我可能会忽略的吗?
回答by Ezio Auditore da Firenze
Look at that: Cannot bulk load. The file "c:\data.txt" does not exist
看看那个: 无法批量加载。文件“c:\data.txt”不存在
Is that file on the SQL Server's C:\
drive??
该文件在 SQL Server 的C:\
驱动器上吗?
SQL BULK INSERT etc. always works only with local drive on the SQL Server machine. Your SQL Server cannot reach onto your own local drive.
SQL BULK INSERT 等始终仅适用于 SQL Server 计算机上的本地驱动器。您的 SQL Server 无法访问您自己的本地驱动器。
You need to put the file onto the SQL Server's C:\ drive and try again.
您需要将该文件放到 SQL Server 的 C:\ 驱动器上,然后再试一次。
回答by Jayan
Bulk import utility syntax is described here
此处描述了批量导入实用程序语法
http://msdn.microsoft.com/en-us/library/ms188365.aspx
http://msdn.microsoft.com/en-us/library/ms188365.aspx
> BULK INSERT [ database_name . [ schema_name ] . | schema_name . ]
> [ table_name | view_name ]
> FROM 'data_file'
> [ WITH
> (
Note on data_file argument says
关于 data_file 参数的说明说
' data_file '
'数据文件'
Is the full path of the data file that contains data to import into the specified table or view. BULK INSERT can import data from a disk (including network, floppy disk, hard disk, and so on).
data_file must specify a valid path from the server on which SQL Server is running. If data_file is a remote file, specify the Universal Naming Convention (UNC) name. A UNC name has the form \Systemname\ShareName\Path\FileName. For example, \SystemX\DiskZ\Sales\update.txt.
是包含要导入到指定表或视图的数据的数据文件的完整路径。BULK INSERT 可以从磁盘(包括网络、软盘、硬盘等)导入数据。
data_file 必须指定来自运行 SQL Server 的服务器的有效路径。如果 data_file 是远程文件,请指定通用命名约定 (UNC) 名称。UNC 名称的格式为 \Systemname\ShareName\Path\FileName。例如,\SystemX\DiskZ\Sales\update.txt。
回答by EMB
I've had this problem before. In addition to checking the file path you'll want to make sure you're referencing the correct file name and file type. Make sure this is indeed a text file that you have saved in the source location and not a word file etc. I got tripped up with .doc and .docx. This is a newb mistake of mine to make but hey, it can happen. Changed the file type and it fixed the problem.
我以前遇到过这个问题。除了检查文件路径之外,您还需要确保引用了正确的文件名和文件类型。确保这确实是您保存在源位置的文本文件,而不是 word 文件等。我被 .doc 和 .docx 绊倒了。这是我犯的一个新错误,但嘿,它可能会发生。更改了文件类型并解决了问题。