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-Enthusiastic
SSC-Enthusiastic (113 reputation)SSC-Enthusiastic (113 reputation)SSC-Enthusiastic (113 reputation)SSC-Enthusiastic (113 reputation)SSC-Enthusiastic (113 reputation)SSC-Enthusiastic (113 reputation)SSC-Enthusiastic (113 reputation)SSC-Enthusiastic (113 reputation)

Group: General Forum Members
Points: 113 Visits: 39

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
SSCertifiable
SSCertifiable (6.3K reputation)SSCertifiable (6.3K reputation)SSCertifiable (6.3K reputation)SSCertifiable (6.3K reputation)SSCertifiable (6.3K reputation)SSCertifiable (6.3K reputation)SSCertifiable (6.3K reputation)SSCertifiable (6.3K reputation)

Group: General Forum Members
Points: 6333 Visits: 1028
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
SSCertifiable
SSCertifiable (6.8K reputation)SSCertifiable (6.8K reputation)SSCertifiable (6.8K reputation)SSCertifiable (6.8K reputation)SSCertifiable (6.8K reputation)SSCertifiable (6.8K reputation)SSCertifiable (6.8K reputation)SSCertifiable (6.8K reputation)

Group: General Forum Members
Points: 6779 Visits: 4371
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
Mr or Mrs. 500
Mr or Mrs. 500 (565 reputation)Mr or Mrs. 500 (565 reputation)Mr or Mrs. 500 (565 reputation)Mr or Mrs. 500 (565 reputation)Mr or Mrs. 500 (565 reputation)Mr or Mrs. 500 (565 reputation)Mr or Mrs. 500 (565 reputation)Mr or Mrs. 500 (565 reputation)

Group: General Forum Members
Points: 565 Visits: 234
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

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