RRinTetons
IS-IT--Management
I've got an Excel workbook with dates in two cells, D9 and D10.
I want to pass those values to an sp called 'SetOTBDates' in SQL Server. The sp works fine when called from within SSMS. So, I wrote a little macro and assigned it to a button. SQL Profiler shows it working to the extent that the sp is called, but it seems to indicate that no parameters are being passed. The profiler shows the statement as:
That doesn't work at all.
Here's the macro as it exists:
From what the profiler shows it appears the sp is being called properly, but it's not getting its parameters. As I understand what's going on, VBA is pushing the two parameters and the name of the sp onto the stack, then popping them off to send to SQL Server when it executes. It appears that I'm not properly pushing the parameters onto the stack.
Pointers?
-
Richard Ray
DBA, Developer, Data Analyst
Jackson Hole Mountain Resort
I want to pass those values to an sp called 'SetOTBDates' in SQL Server. The sp works fine when called from within SSMS. So, I wrote a little macro and assigned it to a button. SQL Profiler shows it working to the extent that the sp is called, but it seems to indicate that no parameters are being passed. The profiler shows the statement as:
Code:
EXEC SetOTBDates default default
That doesn't work at all.
Here's the macro as it exists:
Code:
Sub Button1_Click()
Dim con As ADODB.Connection
Dim cmd As ADODB.Command
Dim rs As ADODB.Recordset
Dim par As String
Dim WSP1 As Worksheet
Set con = New ADODB.Connection
Set cmd = New ADODB.Command
Set rs = New ADODB.Recordset
Application.DisplayStatusBar = True
Application.StatusBar = "Contacting SQL Server..."
' Log into our SQL Server, and run the Stored Procedure
con.Open "Provider=SQLOLEDB;Data Source=MyServer;Initial Catalog=MyDB;Integrated Security=SSPI;Trusted_Connection=Yes;"
cmd.ActiveConnection = con
Dim prmOTBStart As ADODB.Parameter
Dim prmOTBEnd As ADODB.Parameter
' Set up the parameters for our Stored Procedure
cmd.Parameters.Append cmd.CreateParameter("BeginTransactionDate", adVarChar, adParamInput, Range("D9").Text)
cmd.Parameters.Append cmd.CreateParameter("EndTransactionDate", adVarChar, adParamInput, Range("D10").Text)
Application.StatusBar = "Setting Report Dates..."
cmd.CommandText = "SetOTBDates"
Set rs = cmd.Execute(, , adCmdStoredProc)
con.Close
Set con = Nothing
Application.StatusBar = "Data successfully updated."
End Sub
From what the profiler shows it appears the sp is being called properly, but it's not getting its parameters. As I understand what's going on, VBA is pushing the two parameters and the name of the sp onto the stack, then popping them off to send to SQL Server when it executes. It appears that I'm not properly pushing the parameters onto the stack.
Pointers?
-
Richard Ray
DBA, Developer, Data Analyst
Jackson Hole Mountain Resort