Link to home
Start Free TrialLog in
Avatar of probelaw
probelaw

asked on

CreateParameter with varbinary

I am trying to create queries to store a MD5 encoded password in SQL server field with datatype varbinary(50)

I get the error "Application uses a value of the wrong type for the current operation. "

Below is the code.  What's going wrong??

<%

Set cmdSetPassword = Server.CreateObject ("ADODB.Command")
cmdSetPassword.ActiveConnection = MM_sqldb_STRING
cmdSetPassword.CommandText = "UPDATE Users  SET Password = ? WHERE Username = ?"
cmdSetPassword.Parameters.Append cmdSetPassword.CreateParameter("varPassword", 204, 1, 50, MM_IIF(varPassword, varPassword, cmdSetPassword__varPassword & ""))
cmdSetPassword.Parameters.Append cmdSetPassword.CreateParameter("varUsername", 200, 1, 50, MM_IIF(varUsername, varUsername, cmdSetPassword__varUsername & ""))
cmdSetPassword.CommandType = 1
cmdSetPassword.CommandTimeout = 0
cmdSetPassword.Prepared = true
cmdSetPassword.Execute()

%>
Avatar of Anthony Perkins
Anthony Perkins
Flag of United States of America image

>>store a MD5 encoded password in SQL server field with datatype varbinary(50)<<
Any reason to use varbinary?  Why not use varchar?

What is the data type for the value you are assigning to the password?

Avatar of probelaw
probelaw

ASKER

At the moment I believe it is just a binary value resulting from the MD5 function

i.e....

varPassword = MD5(Password)

Should it be declared a specific way?
ASKER CERTIFIED SOLUTION
Avatar of Anthony Perkins
Anthony Perkins
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Changing the datatype in the database to varchar and the parameter to the same works well.  Is there any big difference or risk to doing it this way?

Thanks for the help.