JackSparrow
9 years agoFrequent Contributor
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()