Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Parameters in SQL query on ASP/VBScript

Parameters in SQL query on ASP/VBScript

Scheduled Pinned Locked Moved Database
databasecsharpc++asp-netsysadmin
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    Glenn E Lanier II
    wrote on last edited by
    #1

    I've been given the task of fixing potential (and exploited) SQL-injection errors in an existing ASP (not ASP.NET) project. I can get the following code to execute (no parameters, no concatenation): connString = "Driver={SQL Native Client};Server=server;Database=ACCT;Trusted_Connection=yes;" Set objConn = Server.CreateObject("ADODB.Connection") objConn.Open connString query = "SELECT SystemCode, SystemName FROM tblSystem WHERE Year = 5" Set cmd = Server.CreateObject("ADODB.Command") cmd.CommandText = query cmd.ActiveConnection = objConn Set rs = cmd.Execute However, when I try to convert it to use a parameter, I get an error on the cmd.CreateParameter line of "ADODB.Command (0x800A0BB9) Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another." query = "SELECT SystemCode, SystemName FROM tblSystem WHERE Year = @YEAR" Set cmd = Server.CreateObject("ADODB.Command") cmd.CommandText = query cmd.Parameters.Append cmd.CreateParameter("@YEAR", adInteger, adParamInput, ,5) cmd.ActiveConnection = objConn Set rs = cmd.Execute Any idea how I can make this work, preferably quickly and easily? Thanks. --G

    A F 2 Replies Last reply
    0
    • G Glenn E Lanier II

      I've been given the task of fixing potential (and exploited) SQL-injection errors in an existing ASP (not ASP.NET) project. I can get the following code to execute (no parameters, no concatenation): connString = "Driver={SQL Native Client};Server=server;Database=ACCT;Trusted_Connection=yes;" Set objConn = Server.CreateObject("ADODB.Connection") objConn.Open connString query = "SELECT SystemCode, SystemName FROM tblSystem WHERE Year = 5" Set cmd = Server.CreateObject("ADODB.Command") cmd.CommandText = query cmd.ActiveConnection = objConn Set rs = cmd.Execute However, when I try to convert it to use a parameter, I get an error on the cmd.CreateParameter line of "ADODB.Command (0x800A0BB9) Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another." query = "SELECT SystemCode, SystemName FROM tblSystem WHERE Year = @YEAR" Set cmd = Server.CreateObject("ADODB.Command") cmd.CommandText = query cmd.Parameters.Append cmd.CreateParameter("@YEAR", adInteger, adParamInput, ,5) cmd.ActiveConnection = objConn Set rs = cmd.Execute Any idea how I can make this work, preferably quickly and easily? Thanks. --G

      A Offline
      A Offline
      andyharman
      wrote on last edited by
      #2

      Hi Glen What data-type is the Year column? If it is "smallint" then you should use adSmallint. Regards Andy

      1 Reply Last reply
      0
      • G Glenn E Lanier II

        I've been given the task of fixing potential (and exploited) SQL-injection errors in an existing ASP (not ASP.NET) project. I can get the following code to execute (no parameters, no concatenation): connString = "Driver={SQL Native Client};Server=server;Database=ACCT;Trusted_Connection=yes;" Set objConn = Server.CreateObject("ADODB.Connection") objConn.Open connString query = "SELECT SystemCode, SystemName FROM tblSystem WHERE Year = 5" Set cmd = Server.CreateObject("ADODB.Command") cmd.CommandText = query cmd.ActiveConnection = objConn Set rs = cmd.Execute However, when I try to convert it to use a parameter, I get an error on the cmd.CreateParameter line of "ADODB.Command (0x800A0BB9) Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another." query = "SELECT SystemCode, SystemName FROM tblSystem WHERE Year = @YEAR" Set cmd = Server.CreateObject("ADODB.Command") cmd.CommandText = query cmd.Parameters.Append cmd.CreateParameter("@YEAR", adInteger, adParamInput, ,5) cmd.ActiveConnection = objConn Set rs = cmd.Execute Any idea how I can make this work, preferably quickly and easily? Thanks. --G

        F Offline
        F Offline
        Frank Kerrigan
        wrote on last edited by
        #3

        I think the type is wrong on your parameter, you should be using dbtype.int or SQLdbType.int32

        Grady Booch: I told Google to their face...what you need is some serious adult supervision. (2007 Turing lecture) http://www.frankkerrigan.com/[^]

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups