Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
QTP always returns EOF when querying SQL statement to Access 2K3
#1
Solved: 11 Years, 4 Months, 3 Weeks ago
Hi guys! I have this function there that runs a SQL query to an Access database in order to get the object configuration of a button. However, when it comes to querying the SQL statement, QTP always returns with an empty value. But, when I run the SQL statement using the native SQL compiler of Access 2003, it queries the command successfully, and returns the value that I'm searching for. Can anyone help me solve this?

Code:
    ' ==========================================
    Function AddItem(objWindow, strItem)
        On Error Resume Next

        Const adOpenForwardOnly = 0
        Const adOpenKeyset = 1
        Const adOpenDynamic = 2
        Const adOpenStatic = 3

        strTblName = Environment("Table_Name")
        curPage = objWindow.JavaButton("developer name:=BF.microflow.pageTitle").GetROProperty("attached text")

        Set connAccess = CreateObject("ADODB.Connection")
        Set rsObjects = CreateObject("ADODB.Recordset")
            connAccess.Provider = "Microsoft.JET.OLEDB.4.0"
            connAccess.Open "C:\BFTC\Object Config\BFTC_ObjConf.mdb"

        strSQLObjects = "SELECT * FROM " & strTblName & " WHERE Page='" & curPage & _
                        "' AND FieldName LIKE 'Add_" & strItem & "*' AND " & _
                        "(AttachedText LIKE 'Add*' OR AttachedText LIKE '*>*')"

        ' SELECT * FROM ROLE WHERE Page='Create Role' AND FieldName LIKE 'Add_Permission*' AND (AttachedText LIKE 'Add*' OR AttachedText LIKE '*>*')

        rsObjects.Open strSQLObjects, connAccess, adOpenStatic

        objWindow.JavaButton("attached text:=" & rsObjects.Fields("AttachedText").Value).Click

        connAccess.Close
        Set connAccess = Nothing
        Set rsObjects = Nothing

        strError = Err.Description
        AddItem = ErrorCheck(strError)
    End Function
Reply
#2
Solved: 11 Years, 4 Months, 3 Weeks ago
Hi,

Just make sure u are passing the correct values as variable used in ur query.Try to run the query without using variable, try to pass the hardcoded values and check.

Let me know if hardcoded values help u or not.

Regards,
Sankalp
Reply
#3
Solved: 11 Years, 4 Months, 3 Weeks ago
sometimes because of quotes ..the query string is not properly created..you can put a breakpoint after the query statemnt is created.
Put it in watch..pick up that query and manually check whether it returns values in the database.
Please let me know if you need more help or clarification.
Reply
#4
Solved: 11 Years, 4 Months, 3 Weeks ago
Solved it. The error was with the SQL statement. Looks like QTP can't "understand" the "*" wildcard, instead, I replaced it with the "%" wildcard (which oddly, does not work when querying in Access 2003):

Code:
strSQLObjects = "SELECT * FROM " & strTblName & " WHERE Page='" & curPage & _
                            "' AND FieldName LIKE 'Add_" & strItem & "%' AND " & _
                            "(AttachedText LIKE 'Add%' OR AttachedText LIKE '%>%')"
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Exe invoked through UFT is unable to access IIS and SQL Server service bkdevise 0 2,194 08-25-2015, 05:49 PM
Last Post: bkdevise
  This code does not give total no of links present on page plz help it returns 0 excellentpawan 8 5,725 01-17-2015, 07:49 PM
Last Post: yogi4tech
  parameterize Excel Sheet Name in SQL bjitsidhu 0 2,941 07-20-2014, 08:34 AM
Last Post: bjitsidhu
  Is there a possible way to execute sql in QTP using 'WITH' clause shruthic 0 3,136 04-26-2014, 11:42 PM
Last Post: shruthic
  How to automate MS Access Frontend application through QTP Anchal0604 0 2,390 11-26-2013, 12:40 PM
Last Post: Anchal0604

Forum Jump:


Users browsing this thread: 1 Guest(s)