Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > Must declare the variable...

Reply
Thread Tools

Must declare the variable...

 
 
Ron Hinds
Guest
Posts: n/a
 
      06-16-2010
Trying to do the following Parameterized Query in Classic ASP, I get the
error:

Must declare the variable @Pagetype

Here is the code:

Set oCommLocal = Server.CreateObject("ADODB.Command")
oCommLocal.ActiveConnection = oConn
oCommLocal.CommandType = adCmdText
oCommLocal.CommandText = "SELECT SS FROM WPS WHERE
ValidationID='@ValidationID' AND type=@Pagetype and pagename='@pagename'"
Set oParamLocal = oCommLocal.CreateParameter("@ValidationID", adVarChar,
adParamInput, 50, ValidationID)
oCommLocal.Parameters.Append oParamLocal
Set oParamLocal = oCommLocal.CreateParameter("@Pagetype", adInteger,
adParamInput, 4, PageType)
oCommLocal.Parameters.Append oParamLocal
Set oParamLocal = oCommLocal.CreateParameter("@pagename", adVarChar,
adParamInput, 50, pagename)
oCommLocal.Parameters.Append oParamLocal

Set oRS = oCommLocal.Execute()

Even if I change the order of the parameters (they are named parameters so
order should not matter, right?) I get the same message.


 
Reply With Quote
 
 
 
 
Ron Hinds
Guest
Posts: n/a
 
      06-16-2010
"Bob Barrows" <> wrote in message
news:hvb6f5$p7d$...
> Ron Hinds wrote:
>> Trying to do the following Parameterized Query in Classic ASP, I get
>> the error:
>>
>> Must declare the variable @Pagetype
>>
>> Here is the code:
>>
>> Set oCommLocal = Server.CreateObject("ADODB.Command")
>> oCommLocal.ActiveConnection = oConn

>
> You should use the Set keyword here, given that oConn contains a
> reference to an opened connection object rather than a connection
> string.
> If the latter, you should rewrite this to use an explicit connection
> object, in order to avoid issues brought on by lack of connection
> pooling.
>
>> oCommLocal.CommandType = adCmdText
>> oCommLocal.CommandText = "SELECT SS FROM WPS WHERE
>> ValidationID='@ValidationID' AND type=@Pagetype and
>> pagename='@pagename'" Set oParamLocal =
>> oCommLocal.CreateParameter("@ValidationID", adVarChar, adParamInput,
>> 50, ValidationID)
>> oCommLocal.Parameters.Append oParamLocal
>> Set oParamLocal = oCommLocal.CreateParameter("@Pagetype", adInteger,
>> adParamInput, 4, PageType)
>> oCommLocal.Parameters.Append oParamLocal
>> Set oParamLocal = oCommLocal.CreateParameter("@pagename", adVarChar,
>> adParamInput, 50, pagename)
>> oCommLocal.Parameters.Append oParamLocal
>>
>> Set oRS = oCommLocal.Execute()
>>
>> Even if I change the order of the parameters (they are named
>> parameters so order should not matter, right?) I get the same message.

>
> I've never even tried to use named parameters in ad hoc statements like
> this. Use ? parameter tokens instead:
>
> oCommLocal.CommandText = _
> " ... ValidationID = ? and type = ? and pagename= ?"
>
> And don't even bother with the explicit parameter objects. I only use
> explicit parameters if I'm dealing with a stored procedure that returns
> data via return or output parameters. Use a variant array instead:
>
> arParms = Array(ValidationID, PageType, pagename)
> Set oRS = oCommLocal.Execute(,arParms)


The reason I was using explicit parameter objects is to thwart SQL Injection
attacks. Will this method accomplish the same thing?


 
Reply With Quote
 
 
 
 
Bob Barrows
Guest
Posts: n/a
 
      06-16-2010
Ron Hinds wrote:
> "Bob Barrows" <> wrote in message
> news:hvb6f5$p7d$...
>> Ron Hinds wrote:


>>
>> arParms = Array(ValidationID, PageType, pagename)
>> Set oRS = oCommLocal.Execute(,arParms)

>
> The reason I was using explicit parameter objects is to thwart SQL
> Injection attacks. Will this method accomplish the same thing?


Absolutely. It's the use of parameters that thwarts SQL Injection.
Unnamed parameters are still parameters. Behind the scenes, ADO is
creating those parameter objects, using the values in that variant
array.


--
HTH,
Bob Barrows


 
Reply With Quote
 
Ron Hinds
Guest
Posts: n/a
 
      06-16-2010

"Bob Barrows" <> wrote in message
news:hvb7jt$426$...
> Ron Hinds wrote:
>> "Bob Barrows" <> wrote in message
>> news:hvb6f5$p7d$...
>>> Ron Hinds wrote:

>
>>>
>>> arParms = Array(ValidationID, PageType, pagename)
>>> Set oRS = oCommLocal.Execute(,arParms)

>>
>> The reason I was using explicit parameter objects is to thwart SQL
>> Injection attacks. Will this method accomplish the same thing?

>
> Absolutely. It's the use of parameters that thwarts SQL Injection.
> Unnamed parameters are still parameters. Behind the scenes, ADO is
> creating those parameter objects, using the values in that variant
> array.


Thanks Bob, that worked. But now, when I try to reuse the Command object,
I'm getting an error
Multiple-step_OLE_DB_operation_generated_errors._Check_each _OLE_DB_status_value__if_available._No_work_was_do ne.

All I've done is change the CommandText - this next one only has one
parameter so I tried just sending that one parameter like so:

oCommLocal.Execute(, ValidationID)

Should I be setting it to Nothing and start over between uses?


 
Reply With Quote
 
Bob Barrows
Guest
Posts: n/a
 
      06-16-2010
Ron Hinds wrote:
> "Bob Barrows" <> wrote in message
> news:hvb7jt$426$...
>> Ron Hinds wrote:
>>> "Bob Barrows" <> wrote in message
>>> news:hvb6f5$p7d$...
>>>> Ron Hinds wrote:

>>
>>>>
>>>> arParms = Array(ValidationID, PageType, pagename)
>>>> Set oRS = oCommLocal.Execute(,arParms)
>>>
>>> The reason I was using explicit parameter objects is to thwart SQL
>>> Injection attacks. Will this method accomplish the same thing?

>>
>> Absolutely. It's the use of parameters that thwarts SQL Injection.
>> Unnamed parameters are still parameters. Behind the scenes, ADO is
>> creating those parameter objects, using the values in that variant
>> array.

>
> Thanks Bob, that worked. But now, when I try to reuse the Command
> object, I'm getting an error
>

Multiple-step_OLE_DB_operation_generated_errors._Check_each _OLE_DB_statu
s_value__if_available._No_work_was_done.
>
> All I've done is change the CommandText - this next one only has one
> parameter so I tried just sending that one parameter like so:
>
> oCommLocal.Execute(, ValidationID)
>
> Should I be setting it to Nothing and start over between uses?


Have you closed the recordset before trying to reuse the connection?
Only one open cursor is allowed at a time.

--
HTH,
Bob Barrows


 
Reply With Quote
 
Ron Hinds
Guest
Posts: n/a
 
      06-17-2010

"Bob Barrows" <> wrote in message
news:hvbced$g02$...
> Ron Hinds wrote:
>> "Bob Barrows" <> wrote in message
>> news:hvb7jt$426$...
>>> Ron Hinds wrote:
>>>> "Bob Barrows" <> wrote in message
>>>> news:hvb6f5$p7d$...
>>>>> Ron Hinds wrote:
>>>
>>>>>
>>>>> arParms = Array(ValidationID, PageType, pagename)
>>>>> Set oRS = oCommLocal.Execute(,arParms)
>>>>
>>>> The reason I was using explicit parameter objects is to thwart SQL
>>>> Injection attacks. Will this method accomplish the same thing?
>>>
>>> Absolutely. It's the use of parameters that thwarts SQL Injection.
>>> Unnamed parameters are still parameters. Behind the scenes, ADO is
>>> creating those parameter objects, using the values in that variant
>>> array.

>>
>> Thanks Bob, that worked. But now, when I try to reuse the Command
>> object, I'm getting an error
>>

> Multiple-step_OLE_DB_operation_generated_errors._Check_each _OLE_DB_statu
> s_value__if_available._No_work_was_done.
>>
>> All I've done is change the CommandText - this next one only has one
>> parameter so I tried just sending that one parameter like so:
>>
>> oCommLocal.Execute(, ValidationID)
>>
>> Should I be setting it to Nothing and start over between uses?

>
> Have you closed the recordset before trying to reuse the connection?
> Only one open cursor is allowed at a time.


Yes.


 
Reply With Quote
 
Bob Barrows
Guest
Posts: n/a
 
      06-17-2010
Ron Hinds wrote:
> "Bob Barrows" <> wrote in message
> news:hvbced$g02$...
>> Ron Hinds wrote:
>>> "Bob Barrows" <> wrote in message
>>> news:hvb7jt$426$...
>>>> Ron Hinds wrote:
>>>>> "Bob Barrows" <> wrote in message
>>>>> news:hvb6f5$p7d$...
>>>>>> Ron Hinds wrote:
>>>>
>>>>>>
>>>>>> arParms = Array(ValidationID, PageType, pagename)
>>>>>> Set oRS = oCommLocal.Execute(,arParms)
>>>>>
>>>>> The reason I was using explicit parameter objects is to thwart SQL
>>>>> Injection attacks. Will this method accomplish the same thing?
>>>>
>>>> Absolutely. It's the use of parameters that thwarts SQL Injection.
>>>> Unnamed parameters are still parameters. Behind the scenes, ADO is
>>>> creating those parameter objects, using the values in that variant
>>>> array.
>>>
>>> Thanks Bob, that worked. But now, when I try to reuse the Command
>>> object, I'm getting an error
>>>

>>

Multiple-step_OLE_DB_operation_generated_errors._Check_each _OLE_DB_statu
>> s_value__if_available._No_work_was_done.
>>>
>>> All I've done is change the CommandText - this next one only has one
>>> parameter so I tried just sending that one parameter like so:
>>>
>>> oCommLocal.Execute(, ValidationID)
>>>
>>> Should I be setting it to Nothing and start over between uses?

>>
>> Have you closed the recordset before trying to reuse the connection?
>> Only one open cursor is allowed at a time.

>
> Yes.




Well, I guess you can try setting Prepared to false, but I would not
waste a lot of time getting to the bottom of this:
the simplest thing to do is re-instantiate the Command. There really is
no advantage to re-using the Command, beyond saving a couple lines of
code.


--
HTH,
Bob Barrows


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
"Must declare the scalar variable @Nickname"... Jiggaz ASP .Net 6 11-05-2009 07:01 AM
Must declare the scalar variable '@FirstName' =?Utf-8?B?S2VuIEFkZW5pamk=?= ASP .Net 4 08-17-2007 04:15 AM
Incorrect syntax near '-'.Must declare the scalar variable "@UserName roamnet@yahoo.com ASP .Net 0 05-11-2007 09:17 PM
Must Declare the Scalar Variable error Oded Dror ASP .Net 2 05-28-2006 02:39 PM
Error: Must Declare Variable Boris Zakharin ASP .Net 2 07-22-2003 01:04 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57