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
Highlighted
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
Highlighted
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

View solution in original post

8 REPLIES 8
Highlighted
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
[Hall of Fame]
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
Vegas Thrill Rider
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

Learn SmartBear products in a fun and easy way and prove your knowledge!
>>Participate in the TechCorner Challenge today
Highlighted
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

Learn SmartBear products in a fun and easy way and prove your knowledge!
>>Participate in the TechCorner Challenge today
Highlighted
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.

Highlighted
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

Highlighted
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
[Hall of Fame]
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
Vegas Thrill Rider
Extensions available
Highlighted
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

View solution in original post

Highlighted
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.

New Here?
Join us and watch the welcome video:
Announcements
Join TechCorner Challenge!
Want a fun and easy way to learn TestComplete? Try solving weekly TechCorner challenges and get into the Leaderboard!


Challenge Status

Compare images using the Region Checkpoint

See replies!

Converting UTC TimeDate in an Excel file

See replies!

Compare HTML table with Excel file and correct data in Excel file

Participate!

How to execute remote test and obtain results via Test Runner REST API

Participate!
Top Kudoed Authors