Solved

CreateParameter with varbinary

Posted on 2008-10-12
5
966 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 125 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

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Question has a verified solution.

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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

919 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now