Forum Discussion

JackSparrow's avatar
JackSparrow
Frequent Contributor
8 years ago

Test complete[Python] getting crashed while connecting to database

Hi All ,

 

when i  execute the below function first time it will work fine and will get the output what is expected but when i execute again the same function at the line DBConnection.open() the Test-Complete gets crashed , please help me on this.

 

 

def DB_industrycode():
   plusone= 0
   productqry = "select top 3 prod.prod_code from prod, sysp where sysp.logical_date between prod.effe_stt_date and prod.effe_end_date order by random()"
   AConnection = ADO.CreateADOConnection()
   # Specify the connection string
   AConnection.ConnectionString = "Provider=MSDASQL.1;" + \
   "Data Source=LMk2 Penelope";
   #AConnection.ConnectionString = "Provider=MSDASQL.1;" + \
   #"Data Source=itvuat";
   # Suppress the login dialog box
   AConnection.LoginPrompt = False
   AConnection.Open()
   data_container= []
   data_container2= []
   # Execute a simple query
   RecSet2 =  AConnection.Execute_(productqry)
   RecSet2.MoveFirst();
   while not RecSet2.EOF:  
     
      p = RecSet2.Fields.Item["prod_code"].Value
      data_container2.append(p)
      # rows = rows.append(",")
      #rows.split(",")
      #Log.Message(rows)
      RecSet2.MoveNext()
   
   Log.message('The values extracted from DB are ' + str(data_container2))
   AConnection.Close()
   productcount = len(data_container2)
   Log.Message(str(productcount)) 
   #Log.Message("The product code selected from the above list is " + str(prodcode))
   indcode= []
   for i in range(productcount):
       
       RecSet  =  AConnection.Execute_("select * from ccpy where prod_code="+str(data_container2[i]))
       #RecSet.MoveFirst();
       RecSet.MoveFirst();
       while not RecSet.EOF:  
         # rows1 = ""
          r = RecSet.Fields.Item["industry_code"].Value
          data_container.append(r)
          # rows = rows.append(",")
          #rows.split(",")
          #Log.Message(rows)
          RecSet.MoveNext()
       #Reclen = len(RecSet)
       Log.message(str(data_container))
       
       #data_container=data_container.split(",")
       #count = len(data_container)
       val = data_container[-1]
       Log.Message("The industry code selected from the last is :" + str(val)+ "for the product "+str(data_container2[i]))
       #Log.Message(str(val))
       #val= val[0:10]
       val = val.split("/")
       #Log.Message(val[1])
       val2 = val[1]
       count = len(val2)
       val3 = val2[4:7]
       Temp = len(val3)-len(val3.lstrip('0'))
       if Temp == 2:
           if plusone ==1:
             val3 = int(val3)+2
             val3 = "00"+str(val3)
             Log.Message(str(val3))
           else:
            val3 = int(val3)+1  
            val3 = "00"+str(val3)
            Log.Message(str(val3))
       elif Temp == 1:
           if plusone ==1:
              val3 = int(val3)+2
              val3 = "0"+str(val3)
              Log.Message(str(val3))
           else:
              val3 = int(val3)+1
              val3 = "0"+str(val3)
              Log.Message(str(val3))  
       else:
            if plusone ==1:
              val3 = int(val3)+2
              Log.Message(str(val3))
            else :  
              val3 = int(val3)+1
              Log.Message(str(val3))
          #val2 = val2[1:3]
       newindcode = val[0]+"/"+val2[0:4]+str(val3)+"/"+val[2]
       indcode.append(newindcode)
   Log.Message(str(indcode))
AConnection.Close()

 

6 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    OK, I don't know Python AT ALL... but, one thing I see is that AConnection.Close() is getting called after you populate data container 2... then you execute a query again using the same connection AFTER it's closed to populate data_container without first opening the connection.

    So, I'm not sure EXACTLY why you're getting a crash... but running an execution of a query on a closed connection... I'm surprised this works the first time.

    • JackSparrow's avatar
      JackSparrow
      Frequent Contributor

      tristaanogreya exactly if the mistake is there it must not work first time also but it is working as expected but dont know what happens if i run it again it gets crashed.

       

      And even i tried to connect data base twice separately and open it twice and close simultaneously then also same problem occurs, it got crashed 2nd time.

      • tristaanogre's avatar
        tristaanogre
        Esteemed Contributor

        Well, I'd start by correcting the mistake.  Make sure that all connections are opened and closed where they need to be.

        You say "TestComplete crashed".... I'm assuming that the TC application itself is crashing by that?  If so, do you have a crash dump that you can send off to support?  Usually, when TC crashes, that's your best bet.