Question : Error:Operating system error code 3(The system cannot find the path specified.) doing BulkInser in a SQL Query

Hi,

I get this exception:

Operating system error code 3(The system cannot find the path specified.)


When I try to do Bulk Insert in SQL.

SELECT SUBSTRING(a.line,1,1) as ID,
             SUBSTRING(a.line,2,2000) as Account
            FROM OPENROWSET
                  ( BULK
            'C:\Users\Test\Desktop\DATA.DAT',
            FORMATFILE =
            'C:\Users\Test\Desktop\singlelineformatfile.txt') AS a

If I do on Local Machine with Windows Authentication it works fine, try the same on server with sa and password(UID and PWD).

I get the above error message.


Answer : Error:Operating system error code 3(The system cannot find the path specified.) doing BulkInser in a SQL Query

A few obvious statements... Make sure the data file is on the server, like it is local. As astroutkarsh is saying. Put the file in a folder that is more visible to the SQL Engine for file access. For example, the "C:\Windows\" directory is NOT allowed by the SQL Engine to access there, unless you explicitly tell it to. However, the installation of SQL Server applies the correct permissions for file access to the directory where the DATA files are installed (the .MDF and .LDF files). The .MDF file (Microsoft Data File) is the data file where table data is stored in SQL Server. The .LDF file (Log Data File) is where the data transactions are stored temporarily until they are committed to the table (.MDF).

You're being instructed to put the two files in a new location. If you indicated a different location to install your SQL Data files, then update my location below. Otherwise, if you have applied a standard installation, then the following location will work for you.

Therefore ... move the files accordingly
'C:\Users\Test\Desktop\DATA.DAT' => move to => 'c:\program files\microsoft sql server\90\data\'
'C:\Users\Test\Desktop\singlelineformatfile.txt' => move to => 'c:\program files\microsoft sql server\90\data\'

Then, update your statement and re-execute it.

SELECT SUBSTRING(a.line,1,1) as ID,
             SUBSTRING(a.line,2,2000) as Account
            FROM OPENROWSET
                  ( BULK
            'c:\program files\microsoft sql server\90\data\DATA.DAT',
            FORMATFILE =
            'c:\program files\microsoft sql server\90\data\singlelineformatfile.txt') AS a

To recap, you need to do this (move the files to a new location) to allow the SQL Server Engine to find the files on the server in a folder permitted to seeing the files.
Random Solutions  
 
programming4us programming4us