how to make a db connection created through ADO available to all methods within and outside the unit
SOLVED- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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()
Solved! Go to Solution.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi @sriram_sig,
Please refer to this article - it contains a Python example:
Tanya Yatskovskaya
SmartBear Community and Education Manager
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi @sriram_sig,
Did you find the answer to your question?
Tanya Yatskovskaya
SmartBear Community and Education Manager
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The example which you provided me earlier helps to create db connection, but i also want to use this same connection in other methods
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you. This is exactly what i was looking for.
