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.
Microsoft SQL Server 2008

Avatar of undefined
Last Comment
amitabh04

8/22/2022 - Mon
dbaSQL

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
agriesser

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"
amitabh04

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

Thanks a lot.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
agriesser

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
Alpesh Patel

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
amitabh04

ASKER
Hi,
  What you mean "path is of the SQL Server system " and not other system?

Thanks.