Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sql Bulk Insert -- File does not exist

Tags:

sql

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.

The file is clearly there. Anything I may be overlooking?

like image 272
Nate Pet Avatar asked Apr 04 '12 18:04

Nate Pet


2 Answers

Look at that: Cannot bulk load. The file "c:\data.txt" does not exist

Is that file on the SQL Server's C:\ drive??

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.

You need to put the file onto the SQL Server's C:\ drive and try again.

like image 125
Ezio Auditore da Firenze Avatar answered Oct 23 '22 08:10

Ezio Auditore da Firenze


Bulk import utility syntax is described here

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 '

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.

like image 42
Jayan Avatar answered Oct 23 '22 08:10

Jayan