4

I have the following python code which works fine on run of the function but fails on second run.

import adodbapi

def connect_and_print(input_str):
    print("Function starting...", input_str)

    conna = adodbapi.connect("""
    Provider=MSOLAP;
    Identity Provider=https://login.microsoftonline.com/common, https://analysis.windows.net/powerbi/api, 929d0ec0-7a41-4b1e-bc7c-b754a28bddcc;
    Data Source=pbiazure://api.powerbi.com;
    Initial Catalog=[dataset_id];
    User Id=[username];
    Password=[pass];
    """)

    # Example query
    print('The tables in your database conn are:')
    for name in conna.get_table_names():
        # if name == 'TMSCHEMA_ROLES':
        print(name)
    conna.close()

    print("Function finished", input_str)

#First past connects and runs without issues
connect_and_print("first pass")

#Second pass doesnt connect (Error opening connection to...)
connect_and_print("second pass")

The second pass fails after a long wait with the following error message.

OperationalError: (com_error(-2147352567, 'Exception occurred.', (0, 'Provider', None, None, 1240640, -894947614), None), 'Error opening connection to "\nProvider=MSOLAP.8;\nIdentity Provider=https://login.microsoftonline.com/common, https://analysis.windows.net/powerbi/api, 929d0ec0-7a41-4b1e-bc7c-b754a28bddcc;\nData Source=pbiazure://api.powerbi.com;\nInitial Catalog=[dataset_id];\nUser Id=[username];\nPassword=[pass];\n"')

What do I need to change in the code to be able to run this script without errors?

Mike
  • 144
  • 10

1 Answers1

1

Try to use Provider=MSOLAP (without ".8") This works for me...

  • Unfortunately It doesn't solve the issue. I have reformulated the code in the question without the ".8" after MSOLAP but the issue is still there in the second pass – Mike Dec 08 '21 at 09:59