SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


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


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

Author
Message
leavesandmusic
leavesandmusic
SSC Veteran
SSC Veteran (258 reputation)SSC Veteran (258 reputation)SSC Veteran (258 reputation)SSC Veteran (258 reputation)SSC Veteran (258 reputation)SSC Veteran (258 reputation)SSC Veteran (258 reputation)SSC Veteran (258 reputation)

Group: General Forum Members
Points: 258 Visits: 41

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


aaron.reese
aaron.reese
SSChampion
SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)

Group: General Forum Members
Points: 11594 Visits: 1094
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
HappyGeek
HappyGeek
SSCoach
SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)

Group: General Forum Members
Points: 15375 Visits: 7591
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?

...
Subramaniam Chandrasekar
Subramaniam Chandrasekar
Hall of Fame
Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)

Group: General Forum Members
Points: 3664 Visits: 531
leavesandmusic - Wednesday, January 3, 2018 2:35 PM

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


It says the problem with the driver, So I suspect any win updates were happened on the server ? We'd encountered a similar issue with the excel driver earlier

leavesandmusic
leavesandmusic
SSC Veteran
SSC Veteran (258 reputation)SSC Veteran (258 reputation)SSC Veteran (258 reputation)SSC Veteran (258 reputation)SSC Veteran (258 reputation)SSC Veteran (258 reputation)SSC Veteran (258 reputation)SSC Veteran (258 reputation)

Group: General Forum Members
Points: 258 Visits: 41
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.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum









































































































































































SQLServerCentral


Search