ADODB.Recordset error '800a0bb9' : Arguments are of the wrong type

前端 未结 5 641
轮回少年
轮回少年 2020-12-03 23:25
Set rsPlanID = Server.CreateObject(\"ADODB.Recordset\")
rsPlanID.CursorLocation = adUseClient

strSQL = \"SELECT PlanID FROM ATTJournals WHERE ATTUserDataID = \" &am         


        
相关标签:
5条回答
  • 2020-12-04 00:02
    Function SQL_getRecordset(strQuery)
    
    'On Error Resume Next
     'Create Database connection object
      Set objConnection = CreateObject("ADODB.Connection")
    
      'Create Recordset object
      Set objrecordset = CreateObject("ADODB.Recordset")
    
      'Specify the connection string
      strConnectionstring = "Provider=SQLOLEDB.1;Data Source=*<Server name>*;Initial Catalog=*<database>*;Integrated Security=SSPI"
      objConnection.Open strConnectionstring
    
      'Execute the Query
      Set objrecordset = objConnection.Execute(strQuery)
    
      'Return Recordset
      Set SQL_getRecordset = objrecordset
    
      'Release objects from the memory
      Set objConnection = Nothing
      Set objrecordset = Nothing
    
    End Function
    
    0 讨论(0)
  • 2020-12-04 00:18

    First, when I devoleped application with vbscript I used always the numbers to open a recordset. I recommend following line:

    rsPlanID.Open strSQL, m_objConn, 3, 3
    

    Make sure that you include the file adovbs.inc first. The numbers are conntected to the different types of recordset properties. And don't foregt to open the databse connection first.

    Second, I think you don't need the line

    rsPlanID.CursorLocation = adUseClient 
    

    Thrird, see also this thread. Maybe it is a good template for you.

    0 讨论(0)
  • 2020-12-04 00:23

    Unless you need to navigate back and forth in the recordset, just use the default settings:

    strSQL = "SELECT PlanID FROM ATTJournals WHERE ATTUserDataID = " & ATTUserDataID 
    Set rsPlanID = m_objConn.Execute(strSQL)
    

    Also, your code is wide open for SQL Injection attacks - you better learn about it and change your code to use Parameters instead.

    0 讨论(0)
  • 2020-12-04 00:24

    The most like cause is that you haven't included "ADOVBS.INC" or the equavalent META:-

    <!--METADATA
    TYPE="TypeLib"
    NAME="Microsoft ActiveX Data Objects 2.6 Library"
    UUID="{00000206-0000-0010-8000-00AA006D2EA4}"
    VERSION="2.6"
    -->
    

    Hence the adxxxx constants do not exist. However your primary mistake is not including Option Explicit at the top your script. This will save you bucket loads of time hunting silly mistakes and typos.

    BTW What happens if ATTUserDataID contained "0; DELETE ATTJournals;" ?
    Avoid composing SQL using concatenation like the plague. Search for "ASP SQL Injection" to find examples of using parameterised command objects instead.

    0 讨论(0)
  • 2020-12-04 00:24

    I feel like I searched the whole internet and couldn't find the solution to this problem, and just as I was about to give up, I realized that I had declared my connection variable within an "If" statement and because the if statement did not execute neither did my command to the database giving the error as mentioned in your question.

    0 讨论(0)
提交回复
热议问题