User-718146471 posted
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();
connProc.Open();
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();
cmdProc.ExecuteNonQuery();
connProc.Close();
And the stored proc:
ALTER PROCEDURE [dbo].[sp_ImportData]
(
@FilePath nvarchar(MAX)
)
AS
BEGIN
-- 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 = ',',
ROWTERMINATOR='0x0a',
FIRSTROW = 2
)
So am I missing something? Did I wire this up wrong?