Run-time error '-2147467259 (80004005)': [Microsoft][ODBC SQL Server Driver]Invalid use of default parameter

  • I have code written in vba that inserts data, via Excel, into SQL-Server.  So far everything works well.  However, sometimes it does not work. 

    When it does not work, I receive the following error: Run-time error '-2147467259 (80004005)': [Microsoft][ODBC SQL Server Driver]Invalid use of default parameter. 

    This error message is listed right beside my SQL.Execute command found below.

        Sub A()

        Dim Cn As ADODB.Connection
        Dim Server_Name As String
        Dim Database_Name As String
        Dim SQLStr As String
           
        Server_Name = "MyServer"
        Database_Name = "MyDataBase"
       
        Set Cn = New ADODB.Connection
        Cn.Open "Driver={SQL Server};Server=" & Server_Name & ";Database=" & Database_Name & ";"

        Dim SQL As ADODB.Command
        Set SQL = New ADODB.Command
       
        SQL.CommandText = "UPDATE [Something].[dbo].[tbl_Another_Table] SET [Value] =(?) WHERE [ID] = 1;"
        Dim I As Integer
        For I = 2 To 300
        SQL.CommandText = SQL.CommandText + "UPDATE [Something].[dbo].[tbl_Another_Table] SET [Value] =(?) WHERE [ID] =" & CStr(I) & ";"
        Next I
      
        Dim y As Integer
        For y = 1 To 300
        SQL.Parameters.Append SQL.CreateParameter("Target & CStr(y)", adVarChar, adParamInput, 50, Cells(y + 2, 15).Value)
        Next y
       
        SQL.ActiveConnection = Cn
        SQL.Execute   ####  This is where I always receive my error message :  --ERROR MESSAGE :   Run-time error '-2147467259 (80004005)':
        [Microsoft][ODBC SQL Server Driver]Invalid use of default parameter  ####

        Cn.Close
        Set Cn = Nothing
       
       
        End Sub

  • before you try to execute put the SQLText into a msgPrompt so that you can copy and paste it to management studio.

    I suspect the problem is that you have (?) in the command string rather than the value of the parameter

  • Long time since I touched this but that number indicates a write error, also your code appears to be concatenating all the update statements before appending all of the parameters, as s concatenated string (for 300 records), not sure that is quite correct, but things change, perhaps someone has better grasp of constructs as they should now appear. Unless you have sorted it?

    ...

  • This was removed by the editor as SPAM

  • The version of SQL Server I have is 64 bit.  However, the version of Excel that I have is 32 bit.  
    Based on your experience, would this be the cause of the error?  If so, what steps should I then do?  Is there any documentation on this?  Thank you.

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply