cancel
Showing results for 
Search instead for 
Did you mean: 

how to make a db connection created through ADO available to all methods within and outside the unit

SOLVED
Occasional Contributor

how to make a db connection created through ADO available to all methods within and outside the unit

how to make a db connection created through ADO available to all methods within and outside the unit, when using python as the scripting language

AConnection = ADO.CreateADOConnection()

1 ACCEPTED SOLUTION

Accepted Solutions
Community Hero

Re: how to make a db connection created through ADO available to all methods within and outside the

I'm not a python dev by any means but something like this I think is what you are looking for:

 

connectSting = ""

AConnection = ADO.CreateADOConnection()

def GetConnection():
  if AConnection.Connected == False:
    Log.Message("Connecting")
    AConnection.ConnectionString = connectSting
    # Suppress the login dialog box
    AConnection.LoginPrompt = False    
    AConnection.Open()
  elif AConnection.Connected == True:
    Log.Message("Connected")
  return AConnection
  
def test():
  connection = GetConnection()
  connection = GetConnection()

Then if you want to use that in other script units see: https://support.smartbear.com/testcomplete/docs/scripting/calling-routines/declared-in-another-unit/...


Thanks,
Carson

Click the Accept as Solution button if my answer has helped
8 REPLIES 8
Community Hero

Re: how to make a db connection created through ADO available to all methods within and outside the

You will need to make that connection variable exported from the Python unit.  I don't know Python well but I'm sure there's documentation for it.


Robert Martin
[Community Expert Group]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Extensions available
Community Manager

Re: how to make a db connection created through ADO available to all methods within and outside the

Hi @sriram_sig,

 

Please refer to this article - it contains a Python example:

https://support.smartbear.com/testcomplete/docs/reference/program-objects/ado/createadoconnection.ht...

 

 

 

---------
Tanya Gorbunova
SmartBear Community Manager

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others.↓↓↓↓↓



Join the Ask a SmartBear discussion next Wednesday, February 27th.
We will talk about the biggest test automation gaps!
Community Manager

Re: how to make a db connection created through ADO available to all methods within and outside the

Hi @sriram_sig,

 

Did you find the answer to your question?

---------
Tanya Gorbunova
SmartBear Community Manager

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others.↓↓↓↓↓



Join the Ask a SmartBear discussion next Wednesday, February 27th.
We will talk about the biggest test automation gaps!
Occasional Contributor

Re: how to make a db connection created through ADO available to all methods within and outside the

Not yet. If i want a variable to be available in other methods i assign it to Project variables and then retrieve it when needed. Likewise lets say i have a method which just establishes connection with the db, how can i use this db connection in other methods. I'm stuck here, since i cannot assign this to project variables.

Occasional Contributor

Re: how to make a db connection created through ADO available to all methods within and outside the

The example which you provided me earlier helps to create db connection, but i also want to use this same connection in other methods

Community Hero

Re: how to make a db connection created through ADO available to all methods within and outside the

Rather than a project variable, is there a way to make a variable declared in one Python unit available for others?  In JavaScript, if you export a variable and then use the "requires" call in a subsequent unit, you can access that variable anywhere.

Alternatively, you could create a Script Extension whose sole purpose is to provide an ADO DB connection. that you can then access from anywhere.


Robert Martin
[Community Expert Group]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Extensions available
Community Hero

Re: how to make a db connection created through ADO available to all methods within and outside the

I'm not a python dev by any means but something like this I think is what you are looking for:

 

connectSting = ""

AConnection = ADO.CreateADOConnection()

def GetConnection():
  if AConnection.Connected == False:
    Log.Message("Connecting")
    AConnection.ConnectionString = connectSting
    # Suppress the login dialog box
    AConnection.LoginPrompt = False    
    AConnection.Open()
  elif AConnection.Connected == True:
    Log.Message("Connected")
  return AConnection
  
def test():
  connection = GetConnection()
  connection = GetConnection()

Then if you want to use that in other script units see: https://support.smartbear.com/testcomplete/docs/scripting/calling-routines/declared-in-another-unit/...


Thanks,
Carson

Click the Accept as Solution button if my answer has helped
Occasional Contributor

Re: how to make a db connection created through ADO available to all methods within and outside the

Thank you. This is exactly what i was looking for.

Ask a SmartBear
Top Kudoed Authors