@@ -171,13 +171,22 @@ def create_search_index():
171171create_search_index ()
172172
173173# SQL Server setup
174- DRIVER = "{ODBC Driver 18 for SQL Server}"
175- token_bytes = credential .get_token ("https://database.windows.net/.default" ).token .encode ("utf-16-LE" )
176- token_struct = struct .pack (f"<I{ len (token_bytes )} s" , len (token_bytes ), token_bytes )
177- SQL_COPT_SS_ACCESS_TOKEN = 1256
178- connection_string = f"DRIVER={ DRIVER } ;SERVER={ SQL_SERVER } ;DATABASE={ SQL_DATABASE } ;"
179- conn = pyodbc .connect (connection_string , attrs_before = {SQL_COPT_SS_ACCESS_TOKEN : token_struct })
180- cursor = conn .cursor ()
174+ try :
175+ driver = "{ODBC Driver 18 for SQL Server}"
176+ token_bytes = credential .get_token ("https://database.windows.net/.default" ).token .encode ("utf-16-LE" )
177+ token_struct = struct .pack (f"<I{ len (token_bytes )} s" , len (token_bytes ), token_bytes )
178+ SQL_COPT_SS_ACCESS_TOKEN = 1256
179+ connection_string = f"DRIVER={ driver } ;SERVER={ SQL_SERVER } ;DATABASE={ SQL_DATABASE } ;"
180+ conn = pyodbc .connect (connection_string , attrs_before = {SQL_COPT_SS_ACCESS_TOKEN : token_struct })
181+ cursor = conn .cursor ()
182+ except :
183+ driver = "{ODBC Driver 17 for SQL Server}"
184+ token_bytes = credential .get_token ("https://database.windows.net/.default" ).token .encode ("utf-16-LE" )
185+ token_struct = struct .pack (f"<I{ len (token_bytes )} s" , len (token_bytes ), token_bytes )
186+ SQL_COPT_SS_ACCESS_TOKEN = 1256
187+ connection_string = f"DRIVER={ driver } ;SERVER={ SQL_SERVER } ;DATABASE={ SQL_DATABASE } ;"
188+ conn = pyodbc .connect (connection_string , attrs_before = {SQL_COPT_SS_ACCESS_TOKEN : token_struct })
189+ cursor = conn .cursor ()
181190
182191# Content Understanding client
183192cu_credential = AzureCliCredential (process_timeout = 30 )
0 commit comments