Link to home
Start Free TrialLog in
Avatar of amitabh04
amitabh04

asked on

bulk insert

Hi,
 
1) I am trying to execute the following in query analyzer. The file c:\converted.txt exists on the server. I am actually logged on the server but get error message "Cannot bulk load. The file "c:\converted.txt" does not exist."


BULK INSERT winpayuncashed FROM 'c:\converted.txt'
   WITH (
      DATAFILETYPE = 'char',
      FIELDTERMINATOR = ',',
      ROWTERMINATOR = '\n'
);
GO

2) How can I file path as parameter in the command.

Thanks a lot for your help.
Avatar of dbaSQL
dbaSQL
Flag of United States of America image

Don't believe you can do that with the filename, without dynamic sql.  Check this out:
https://www.experts-exchange.com/questions/23037605/Problem-Passing-a-Path-Filename-as-an-Input-Parameter-for-a-Bulk-Insert.html
Hello there,

to use the filepath as a parameter you would have to create a stored procedure for the bulk import like this:

Create Procedure dbo.bulkImportwinpayuncashed(@FilePath varchar(300))

as

BULK INSERT winpayuncashed FROM ''' +@FilePath+'''
   WITH (
      DATAFILETYPE = 'char',
      FIELDTERMINATOR = ',',
      ROWTERMINATOR = '\n'
);

Then you should be able to run the following command:

exec bulkImportwinpayuncashed "C:\converted.txt"
Avatar of amitabh04
amitabh04

ASKER

Hi,
  Still get error message "Cannot bulk load. The file "c:\converted.txt" does not exist"

Thanks a lot.
Is the user running this script able to access the location where the file is stored? Most of the times, SQL is running under a system account or a different account than the user logged on to the server, so maybe it's a simple permission issue? Can you try to put the converted.txt file into the same directory where your SQL database resides? And then just use the path "converted.txt" without any absolute path names? It should try to read the file from within the SQL data directory then.
ASKER CERTIFIED SOLUTION
Avatar of Alpesh Patel
Alpesh Patel
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi,
  What you mean "path is of the SQL Server system " and not other system?

Thanks.