title: SQL Server stored procedure with parameters invoked from Excel event
body: <p>I'm using Excel 2007 and SQL Server 2008 R2 Express. </p>
  
  <p>I'm trying to invoke my SQL Server stored procedure from Excel event <code>Worksheet.Change</code> in VBA. I have one sheet and I'm invoking the stored procedure with 3 parameters. </p>
  
  <p>While invoking this stored procedure I'm getting error :</p>
  
  <blockquote>
    <p>Run-time error '-2147217900 (80040e14)'<br>
    Syntax error or access violation</p>
  </blockquote>
  
  <p>My Excel script code so far :</p>
  
  <pre><code>Private Sub Worksheet_Change(ByVal Target As Range)
  
  If Target.Address = "$D$4" Then
  
      Dim conn As ADODB.Connection
      Set conn = New ADODB.Connection
  
      Dim cmd As ADODB.Command
      Set cmd = New ADODB.Command
  
      conn.ConnectionString = "Provider='SQLOLEDB'; " &amp; _
                              "Data Source=compname\sqlservername; " &amp; _
                              "Initial Catalog=databasename; " &amp; _
                              "User Id= sa; " &amp; _
                              "Password=****"
  
  
      conn.Open
  
      cmd.ActiveConnection = conn
      cmd.CommandType = adCmdStoredProc
      cmd.CommandText = "Test1 @zmienna1= " &amp; CStr(Range("D4").Value) &amp; _
                              " @zmienna2= " &amp; CStr(Range("D4").Value) &amp; _
                              " @zmienna3= " &amp; CStr(Range("D4").Value)
  
  
  
      cmd.Execute 'error
      conn.Close
  
      Set conn = Nothing
      Set cmd = Nothing
  
  End If
  End Sub
  </code></pre>
  
  <p>I'm getting error on the <code>cmd.Execute</code> line when I'm changing D4 cell. </p>
  
  <p>What am I missing ? Do I have to use <code>Parameters</code> collection of the <code>ADODB.Command</code> object when I'm using a stored procedure with parameters? </p>
  
  <p>If yes - can anyone provide code sample? Could anyone help please ? Thanks! </p>