Forum Discussion

royd's avatar
royd
Regular Contributor
8 years ago
Solved

if else error - (SQL query)

I am getting an error when running flowing script:

 

 

var dbObj = ADO.CreateADOQuery();
dbObj.ConnectionString = "Provider=SQLOLEDB;Server=xxx.xx.xxx.xx;Database=THC_AppServices;User Id=user;Password=password";
dbObj.SQL = "SELECT [Group], [Key], DescLong FROM [System] WHERE [Group] = 'DirectedLogin' AND [Key] = 'ID";
queryResult = dbObj;
dbObj.Open();
//log updated values
dbObj.First();
while (! dbObj.EOF)
{
// Insert the field value into the test log
Log.Checkpoint("Current " + "\'" + dbObj.FieldByName("Key").AsString + "\'" + " value for 'DescLong' is set to " + "\'" + dbObj.FieldByName("DescLong").AsString + "\'.");
// Move to the next record
dbObj.Next();
}dbObj.Close();

if (dbObj.FieldByName("DescLong").AsString === "id_DIRECTED_LOGIN_DISABLED")  //line 27
{
L_Activate_DL.activateDL();
}
else
{
Log.Event("Driected Login already activated!");
}

 

 

The log: Current 'ID' value for 'DescLong' is set to 'id'. 11:18:41 Normal

 

 

The error:
Error location:
Unit: "SWCE9 Smoke Test \Script\A11020_Access_IP"
Line: 27 Column: 3.

 

I am new to JScript. Using TestComplete v12. No idea what am I doing wrong? Also, what does "Column: 3" mean, can someone explain please?

 

Thanks.

 

Dave

  • royd's avatar
    royd
    8 years ago

    Hi Robert

     

    Thank you for pointing that out. I seldom make these types of mistake, I would not be surprised at all. So, I double checked. It is fine for a change! :) I guess I messed up while pasting the code.

     

    Thank you for the suggestion.

7 Replies

  • Marsha_R's avatar
    Marsha_R
    Champion Level 3

    Line: 27 Column: 3. is to tell you that the error detected is on line 27 and 3 characters over from the left.

     

    First, is this the whole error and the whole script?  I don't see 27 lines in what you posted.  

     

    Also, sometimes a problem is actually before the bit where the error is flagged, so don't count on that line/column being precise.

    • royd's avatar
      royd
      Regular Contributor

      Hi Marsha

       

      Line 27 is:

       

       

      if (dbObj.FieldByName("DescLong").AsString === "id_DIRECTED_LOGIN_DISABLED")  //line 27

       commented at the end of line as "//line27"

       

      Also, I ran the script without if - else portion, runs fine, logs the expected value from the table. 

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    I THINK the problem is here:

    dbObj.SQL = "SELECT [Group], [Key], DescLong FROM [System] WHERE [Group] = 'DirectedLogin' AND [Key] = 'ID";
    

    Check the what I marked in bold. If this is a direct copy and paste from your code, you have an improperly closed string.  Change that line to the following:

    dbObj.SQL = "SELECT [Group], [Key], DescLong FROM [System] WHERE [Group] = 'DirectedLogin' AND [Key] = 'ID'";
    • royd's avatar
      royd
      Regular Contributor

      Hi Robert

       

      Thank you for pointing that out. I seldom make these types of mistake, I would not be surprised at all. So, I double checked. It is fine for a change! :) I guess I messed up while pasting the code.

       

      Thank you for the suggestion.

      • tristaanogre's avatar
        tristaanogre
        Esteemed Contributor

        DOH!  I see it.... should have noticed this before...

        You are closing your dbObj... you call "dbObj.Close" on what looks to be line 25.  Well, when you close the object, you can't reference the values of the fields of the object.

        Move the close AFTER your if logic and see if that corrects it.