views:

132

answers:

1

I wanted to insert data in a table from a text file where it is stored in csv format to a sql server table. For that, I am using bulk-insert statement. Now I need to specify the file name in "From" clause. I don't want to use networked locations or local locations over there. I want to upload my text file in the same directory as my executable file and give a relative path to it. Is it possible???

+1  A: 

I don't think so. I just tried

SELECT BulkColumn
FROM   OPENROWSET(BULK'files\doesnotexist.txt',SINGLE_BLOB)x;

And looked at it in Process Monitor

And it was looking for C:\WINDOWS\system32\files\doesnotexist.txt so I think you would need to put in the full path.

Martin Smith
Thanks for the reply. So can I use Sqlbulkcopy in c# to achieve my objectives then ???
Anant
Probably - but surely C# must have some command to retrieve the applications current directory that you can just append?
Martin Smith
okay. Thanks a lot.
Anant