Forum Discussion

sriram_sig's avatar
sriram_sig
Contributor
6 years ago

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()
  • cunderw's avatar
    cunderw
    6 years ago

    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/python.html