Solved

CreateParameter with varbinary

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
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 SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

758 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

22 Experts available now in Live!

Get 1:1 Help Now