INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Converting data connections to use parameters

Converting data connections to use parameters

(OP)
Hello,

Currently in process of updating a site and fixing some quick security loopholes prior to a much more thorough sweep. ASP isnt my strong point and I was wondering if someone could show me the proper changes to make to this connection to make it call its stored procedure using parameters?  

<%  Set conn = Server.CreateObject("ADODB.Connection")
    conn.CursorLocation = adUseServer
    conn.open cStr_Tank
    sql = "EXECUTE ""dbo"".""Rpt_TanksQuery"" " & Request.QueryString("TankID")
    Set rs = Server.CreateObject("ADODB.Recordset")
    rs.Open sql, conn, adOpenForwardOnly, adLockReadOnly
%>

RE: Converting data connections to use parameters

And the database in use would be ???

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum

RE: Converting data connections to use parameters

(OP)
Chris,

SQL Sever 2008?

Here is another example


Original;
<%  Set conn = Server.CreateObject("ADODB.Connection")
    conn.CursorLocation = adUseServer
    conn.open cStr_Local
    sql ="dbo.MyServiceHist @MyID='" & Request.QueryString("My") & "',@BeginDate='" & Request.QueryString("BeginDate") & "',@EndDate='"  & Request.QueryString("EndDate") & "'"
    Set rs = Server.CreateObject("ADODB.Recordset")
    rs.Open sql, conn, adOpenForwardOnly, adLockReadOnly
%>


Updated;
<%  Set conn = Server.CreateObject("ADODB.Connection")
    conn.CursorLocation = adUseServer
    conn.open cStr_Local
    Set cmd = Server.CreateObject("ADODB.Command")
    cmd.ActiveConnection = conn
    cmd.CommandText = "dbo.MyServiceHist"
    cmd.CommandType = adCmdStoredProc
    set Myid = cmd.CreateParameter("MyID",adVarChar, adParamInput, 20,Request.QueryString("My") )
    set BeginDate = cmd.CreateParameter("BeginDate",adDateTime, adParamInput, Request.QueryString("BeginDate") )
    set EndDate = cmd.CreateParameter("EndDate", adDateTime , adParamInput, Request.QueryString("EndDate") )
    Set rs = cmd.Execute

%>

Getting type mismatch on this.  

RE: Converting data connections to use parameters

(OP)
Nm. I got it.

<%  Set conn = Server.CreateObject("ADODB.Connection")
    conn.CursorLocation = adUseServer
    conn.open cStr_Local
    Set cmd = Server.CreateObject("ADODB.Command")
    cmd.ActiveConnection = conn
    cmd.CommandText = "dbo.MyServiceHist"
    cmd.CommandType = adCmdStoredProc
    cmd.Parameters.Refresh
    cmd.Parameters(1).Value=Request.QueryString("My")
    cmd.Parameters(2).Value=Request.QueryString("BeginDate")
    cmd.Parameters(3).Value=Request.QueryString("EndDate")
    Set rs = cmd.Execute

%>

This works for the most part. For some reason the initial two records in the result set are getting suppressed.  

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close