Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

CreateParameter with varbinary

Posted on 2008-10-12
5
Medium Priority
?
1,003 Views
Last Modified: 2008-10-12
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()

%>
0
Comment
Question by:probelaw
  • 3
  • 2
5 Comments
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 22697897
>>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?

0
 

Author Comment

by:probelaw
ID: 22698105
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?
0
 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 500 total points
ID: 22698937
>>At the moment I believe it is just a binary value resulting from the MD5 function<<
Since there is no data type called "binary" in VB I would suggest you set it to variant when you pass it to a parameter in a stored procedure defined as varbinary.  However I would suggest you instead define it as string and change the stored procedure and table to use a varchar data type.
0
 

Author Comment

by:probelaw
ID: 22698992
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.
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 22699028
No.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Ready to get certified? Check out some courses that help you prepare for third-party exams.
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

876 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question