Skip to content

Commit 6f493b5

Browse files
fix: add ODBC Driver 17 for sql when process custom data
2 parents 73e669e + 355fee2 commit 6f493b5

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

infra/scripts/index_scripts/04_cu_process_custom_data.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -171,13 +171,22 @@ def create_search_index():
171171
create_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
183192
cu_credential = AzureCliCredential(process_timeout=30)

0 commit comments

Comments
 (0)