我有下面的python代码,它在运行函数时运行良好,但在第二次运行时失败。
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")
经过长时间等待后,第二次传递失败,并显示以下错误消息。
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"')
为了能够在没有错误的情况下运行此脚本,我需要在代码中更改什么?
尝试使用Provider=MSOLAP(不带".8"(这对我有用…