Skip to content

Commit 782d633

Browse files
feat: Update ODBC Driver references to version 18 across documentation and code
1 parent b25b0f4 commit 782d633

File tree

8 files changed

+40
-27
lines changed

8 files changed

+40
-27
lines changed

documents/DeploymentGuide.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ If you're not using one of the above options for opening the project, then you'l
150150
- [Python 3.9 to 3.11](https://www.python.org/downloads/)
151151
- [Docker Desktop](https://www.docker.com/products/docker-desktop/)
152152
- [Git](https://git-scm.com/downloads)
153+
- [Microsoft ODBC Driver 18](https://learn.microsoft.com/en-us/sql/connect/odbc/download-odbc-driver-for-sql-server?view=sql-server-ver16) for SQL Server.
153154

154155
2. Clone the repository or download the project code via command-line:
155156

documents/LocalDebuggingSetup.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Install these tools before you start:
1616
- [Node.js (LTS)](https://nodejs.org/en).
1717
- [Git](https://git-scm.com/downloads).
1818
- [Azure Developer CLI (azd) v1.18.0+](https://learn.microsoft.com/en-us/azure/developer/azure-developer-cli/install-azd).
19-
- [Microsoft ODBC Driver 17](https://learn.microsoft.com/en-us/sql/connect/odbc/download-odbc-driver-for-sql-server?view=sql-server-ver16) for SQL Server.
19+
- [Microsoft ODBC Driver 18](https://learn.microsoft.com/en-us/sql/connect/odbc/download-odbc-driver-for-sql-server?view=sql-server-ver16) for SQL Server.
2020

2121

2222
## Setup Steps

infra/scripts/index_scripts/03_cu_process_data_text.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
print("Azure Search setup complete.")
6868

6969
# SQL Server setup
70-
driver = "{ODBC Driver 17 for SQL Server}"
70+
driver = "{ODBC Driver 18 for SQL Server}"
7171
token_bytes = credential.get_token("https://database.windows.net/.default").token.encode("utf-16-LE")
7272
token_struct = struct.pack(f"<I{len(token_bytes)}s", len(token_bytes), token_bytes)
7373
SQL_COPT_SS_ACCESS_TOKEN = 1256

infra/scripts/index_scripts/04_cu_process_custom_data.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ def create_search_index():
175175
create_search_index()
176176

177177
# SQL Server setup
178-
DRIVER = "{ODBC Driver 17 for SQL Server}"
178+
DRIVER = "{ODBC Driver 18 for SQL Server}"
179179
token_bytes = credential.get_token("https://database.windows.net/.default").token.encode("utf-16-LE")
180180
token_struct = struct.pack(f"<I{len(token_bytes)}s", len(token_bytes), token_bytes)
181181
SQL_COPT_SS_ACCESS_TOKEN = 1256

src/api/ApiApp.Dockerfile

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ RUN apk add --no-cache --virtual .build-deps \
1111
opus-dev \
1212
libvpx-dev
1313

14-
# Download and install Microsoft ODBC Driver and MSSQL tools
15-
RUN curl -O https://download.microsoft.com/download/e/4/e/e4e67866-dffd-428c-aac7-8d28ddafb39b/msodbcsql17_17.10.6.1-1_amd64.apk \
16-
&& curl -O https://download.microsoft.com/download/e/4/e/e4e67866-dffd-428c-aac7-8d28ddafb39b/mssql-tools_17.10.1.1-1_amd64.apk \
17-
&& apk add --allow-untrusted msodbcsql17_17.10.6.1-1_amd64.apk \
18-
&& apk add --allow-untrusted mssql-tools_17.10.1.1-1_amd64.apk \
19-
&& rm msodbcsql17_17.10.6.1-1_amd64.apk mssql-tools_17.10.1.1-1_amd64.apk
14+
# Download and install Microsoft ODBC Driver 18 and MSSQL tools (latest release)
15+
RUN curl -O https://download.microsoft.com/download/fae28b9a-d880-42fd-9b98-d779f0fdd77f/msodbcsql18_18.5.1.1-1_amd64.apk \
16+
&& curl -O https://download.microsoft.com/download/7/6/d/76de322a-d860-4894-9945-f0cc5d6a45f8/mssql-tools18_18.4.1.1-1_amd64.apk \
17+
&& apk add --allow-untrusted msodbcsql18_18.5.1.1-1_amd64.apk \
18+
&& apk add --allow-untrusted mssql-tools18_18.4.1.1-1_amd64.apk \
19+
&& rm msodbcsql18_18.5.1.1-1_amd64.apk mssql-tools18_18.4.1.1-1_amd64.apk
2020

2121
# Set the working directory inside the container
2222
WORKDIR /app

src/api/common/config/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def __init__(self):
1616
self.sqldb_database = os.getenv("SQLDB_DATABASE")
1717
self.sqldb_server = os.getenv("SQLDB_SERVER")
1818
self.sqldb_username = os.getenv("SQLDB_USERNAME")
19-
self.driver = "{ODBC Driver 17 for SQL Server}"
19+
self.driver = "{ODBC Driver 18 for SQL Server}"
2020
self.mid_id = os.getenv("SQLDB_USER_MID")
2121

2222
# Azure OpenAI configuration

src/api/common/database/sqldb_service.py

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ async def get_db_connection():
1717
database = config.sqldb_database
1818
username = config.sqldb_username
1919
password = config.sqldb_database
20-
driver = config.driver
2120
# mid_id = config.mid_id
2221
mid_id = config.azure_client_id
2322

@@ -33,22 +32,35 @@ async def get_db_connection():
3332
)
3433
SQL_COPT_SS_ACCESS_TOKEN = 1256
3534

36-
# Set up the connection
37-
connection_string = f"DRIVER={driver};SERVER={server};DATABASE={database};"
38-
conn = pyodbc.connect(
39-
connection_string, attrs_before={SQL_COPT_SS_ACCESS_TOKEN: token_struct}
40-
)
41-
42-
logging.info("Connected using Azure Credential")
43-
return conn
44-
except pyodbc.Error as e:
35+
# Try both ODBC Driver 18 and 17
36+
conn = None
37+
for driver in ["{ODBC Driver 18 for SQL Server}", "{ODBC Driver 17 for SQL Server}"]:
38+
try:
39+
connection_string = f"DRIVER={driver};SERVER={server};DATABASE={database};"
40+
conn = pyodbc.connect(
41+
connection_string, attrs_before={SQL_COPT_SS_ACCESS_TOKEN: token_struct}
42+
)
43+
logging.info(f"Connected using Azure Credential with {driver}")
44+
return conn
45+
except pyodbc.Error:
46+
continue
47+
48+
if conn is None:
49+
raise RuntimeError("Unable to connect using ODBC Driver 18 or 17 with Azure Credential")
50+
except Exception as e:
4551
logging.error("Failed with Azure Credential: %s", str(e))
46-
conn = pyodbc.connect(
47-
f"DRIVER={driver};SERVER={server};DATABASE={database};UID={username};PWD={password}",
48-
timeout=5)
49-
50-
logging.info("Connected using Username & Password")
51-
return conn
52+
# Try username/password authentication with both drivers
53+
for driver in ["{ODBC Driver 18 for SQL Server}", "{ODBC Driver 17 for SQL Server}"]:
54+
try:
55+
conn = pyodbc.connect(
56+
f"DRIVER={driver};SERVER={server};DATABASE={database};UID={username};PWD={password}",
57+
timeout=5)
58+
logging.info(f"Connected using Username & Password with {driver}")
59+
return conn
60+
except pyodbc.Error:
61+
continue
62+
63+
raise RuntimeError("Unable to connect using ODBC Driver 18 or 17. Install driver msodbcsql17/18.")
5264
finally:
5365
if credential and hasattr(credential, "close"):
5466
await credential.close()

src/tests/api/common/config/test_config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def test_config_initialization(mock_env_vars):
3636
assert config.sqldb_database == "test_db"
3737
assert config.sqldb_server == "test_server"
3838
assert config.sqldb_username == "test_user"
39-
assert config.driver == "{ODBC Driver 17 for SQL Server}"
39+
assert config.driver == "{ODBC Driver 18 for SQL Server}"
4040
assert config.mid_id == "test_mid"
4141

4242
# Azure OpenAI config

0 commit comments

Comments
 (0)