Solved

CreateParameter with varbinary

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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to share SSIS Package? 6 37
ASP/VB email question 4 35
Need help how to find where my error is in UFD 6 30
MS SQL Server COnditional Where statement 7 59
Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.

777 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