Last post Oct 21, 2016 03:41 PM by bbcompent1
Oct 21, 2016 03:29 PM|bbcompent1|LINK
Hey folks, I'm generally a logical person and this error would make sense if I wasn't providing a value for the proc parameter. The error I get is:
Cannot bulk load. The file "' + @FilePath + '" does not exist.
However, the value of the parameter is a file path that I am providing; it does have the expected string value. So I'm completely baffled as to what it wants. Here's my c# Stored Proc code:
string KickOff = "sp_ImportData";
SqlConnection connProc = new SqlConnection(_csCVEMIDB);
SqlCommand cmdProc = new SqlCommand();
cmdProc.Connection = connProc;
cmdProc.CommandTimeout = 0;
cmdProc.CommandType = System.Data.CommandType.StoredProcedure;
cmdProc.Parameters.AddWithValue("@FilePath", csvPath.ToString()); // csvPath has the correct path in debugger
cmdProc.CommandText = KickOff.ToString();
And the stored proc:
ALTER PROCEDURE [dbo].[sp_ImportData]
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
CREATE TABLE #ImportData
... -- Taking out sensitive bits - there are table vars here
DECLARE ... -- sensitive bits scrubbed - trust me this part of the proc works fine if I can pass a variable to it
-- Insert statements for procedure here with parameter @FilePath
BULK INSERT #ImportData from ''' + @FilePath + ''' WITH
FIELDTERMINATOR = ',',
FIRSTROW = 2
So am I missing something? Did I wire this up wrong?
Oct 21, 2016 03:33 PM|cninjas|LINK
I am not sure whether this is the problem. Just a thought. May be the file doesnot exist in the database hard disk? the file should be physically present in the db for this to be updated.
Oct 21, 2016 03:41 PM|bbcompent1|LINK
Never mind, I figured it out. I was specifying the path but not the filename in addition. Brain fart Friday I guess LOL