I need to modify someone else’s VB code, and I don’t have much experience with VB6.
I need to call a SQL2000 stored procedure using ADODB. One of the parameters is of type Binary and it’s giving me problems. Every time I create the parameter, I get an error “Application uses a value of the wrong type for the current operation”. The error happens at the cmd.parameter.append line, it doesn’t even give me a chance call the cmd.execute.
Dim HexPassword As String
Dim BinPassword As String
Dim AsciiCode As Integer
Dim unitDigit As String
Dim TensDigit As String
Set obj_hash = New EDCrypt
' Returns Hash of password hex encoded
HexPassword = obj_hash.GetTextHash(Trim(txtPassword.text), haSHA1)
' Converts Hex Encoded string to Binary encoded string
Dim i As Integer
For i = 1 To 40 Step 2
unitDigit = Mid(HexPassword, i + 1, 1)
TensDigit = Mid(HexPassword, i, 1)
AsciiCode = HexStrtoInt(TensDigit + unitDigit)
BinPassword = BinPassword + Chr(AsciiCode)
Next i
conn.Open ConnectionString
Dim cmd As ADODB.Command
Set cmd = New ADODB.Command
Set cmd.ActiveConnection = conn
cmd.CommandType = adCmdStoredProc
cmd.CommandText = "ValidatePasswordNew"
cmd.Parameters.Append cmd.CreateParameter("LoginID", adVarChar, adParamInput, 30, UserID)
cmd.Parameters.Append cmd.CreateParameter("ShaPassword", adBinary, adParamInput, 20, BinPassword)
Try this for your string concatenation:
+is not the right string concatenation operator, and usingChrBshould convince VB and ADO that you’re really passing it binary data, not character data.There’s also a chance DOK is right about the size. You can try setting the size to something you’re certain is longer than you need, or you can probably get around setting the size at all by splitting the operation into two statements:
It’s weird, but it’s worked for me in the past.
Just for added emphasis in case someone sees this again: the
sizeproperty onParameterobjects does not have to match the exact byte length of your argument; it merely has to be at least big enough to hold your argument.