Click here to Skip to main content
15,894,343 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I am filling database table from multiple txt file but it's showing eror, my datatable did not fill.
SQL
CREATE TABLE #files (name varchar(200) NULL, sql varchar(7000) NULL)

INSERT #files(name)
   exec master..xp_cmdshell 'dir /b C:\AdminDBBOM\*.TXT'

DELETE #files WHERE coalesce(name, '') NOT LIKE '%.TXT%'

UPDATE #files
SET   sql  = 'BULK INSERT BaaN_BOM FROM ''' + name + ''' WITH (' +
             'FIRSTROW=2, FIELDTERMINATOR = ''|'',' +
             'ROWTERMINATOR = ''\n'')'

DECLARE @sql varchar(8000)

DECLARE cur CURSOR STATIC LOCAL FOR
   SELECT sql FROM #files

OPEN cur

WHILE 1 = 1
BEGIN
   FETCH cur INTO @sql
   IF @@fetch_status <> 0
      BREAK

   EXEC(@sql)
END

DEALLOCATE cur


Error:-
(6 row(s) affected)

(2 row(s) affected)

(10 row(s) affected)
Msg 4860, Level 16, State 1, Line 1
Cannot bulk load. The file "1.TXT" does not exist.
Msg 4860, Level 16, State 1, Line 1
Cannot bulk load. The file "2.TXT" does not exist.
Msg 4860, Level 16, State 1, Line 1
Cannot bulk load. The file "3.TXT" does not exist.
Msg 4860, Level 16, State 1, Line 1
Cannot bulk load. The file "4.TXT" does not exist.

How can be possible?
Please help me.

Thank You.
Ankit Agarwal
Software Engineer
Posted

The error message is pretty specific:
Cannot bulk load. The file "1.TXT" does not exist.

The most likely reasons are that either
1) The files are not on the same computer as the SQL server instance (which it would have to be, unless the folder is shared to the SQL computer, but them you wouldn't be looking as "C:\" for your files)
2) If the files are on teh right computer, then the folder probably does not have the required permissions for SQL server to access them under the user ID it is executing as. Have a look here: Backing up an SQL Database in C#[^] under the section "So, It'll Work Now?" - it should help.
 
Share this answer
 
This Error defined whether that concern file is not in defined location. Or if you using an instance of sql server you may unable to insert from your local PC. please try your action into where that main sql server running system.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900