Executing Store Procedure containig Bulk Insert Command with macro/VBA excel 2010

hpm73

New Member
Joined
Aug 14, 2012
Messages
1
Hello everyone and thanks in advance for your help. My first post here, it's been a while since I'm working around this issue and need your help.
I have a Store procedure wich has a Bulk Insert command using dynamic SQL that works ok when executed from SQLManagmentStudio. The SP is included bellow (it has one parameter which I want to complete with the info contained in a cell, excel 2010). I'm using a Macro and VBA to execute the SP and send the parameter (see macro bellow, the range in B2 has the path to the .csv file). Unfortunatelly the macro does not work and sends the following error.

"The Query did not run, or the database table could not be opened"

This same workbook has other macros connecting with the same data base but this one doesn't work.. any idea? THANKS!!!!

Store Procedure:

ALTER PROCEDURE [dbo].[sp_Import_CSV]
@PathFileName varchar(100)

AS
DECLARE @SQL varchar (1000)
DELETE FROM Import_Form
SET @SQL = "BULK INSERT Import_Form FROM '"+@PathFileName+"' WITH(FIELDTERMINATOR = ',', ROWTERMINATOR = ',\n')"
EXEC (@SQL)

Macro:

Sub Import()
With ActiveWorkbook.Connections("IMP_csv").OLEDBConnection
.CommandText = "EXECUTE dbo.sp_Import_CSV '" & Range("B2").Value & "' "
End With
ActiveWorkbook.Connections("IMP_csv").Refresh

End Sub
 

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top