@@ -87,26 +87,26 @@ Update your application following the tutorial [Migrate a Java application to us
87
87
88
88
1. Get the Azure SQL Database connection configurations from the environment variable added by Service Connector. When using the code below, uncomment the part of the code snippet for the authentication type you want to use.
89
89
` ` ` python
90
- import os;
90
+ import os
91
91
import pyodbc
92
92
93
93
server = os.getenv(' AZURE_SQL_SERVER' )
94
94
port = os.getenv(' AZURE_SQL_PORT' )
95
95
database = os.getenv(' AZURE_SQL_DATABASE' )
96
96
authentication = os.getenv(' AZURE_SQL_AUTHENTICATION' )
97
97
98
- # Uncomment the following lines according to the authentication type.
98
+ # Uncomment the following lines according to the authentication type. Customize the driver version as you want.
99
99
# For system-assigned managed identity.
100
- # connString = f'Driver={{ODBC Driver 18 for SQL Server}};Server={server},{port};Database={database};Authentication={authentication};Encrypt=yes;'
100
+ # connString = f'Driver={{ODBC Driver 17 for SQL Server}};Server={server},{port};Database={database};Authentication={authentication};Encrypt=yes;TrustServerCertificate=no;Connection Timeout=30 '
101
101
102
102
# For user-assigned managed identity.
103
103
# user = os.getenv('AZURE_SQL_USER')
104
- # connString = f'Driver={{ODBC Driver 18 for SQL Server}};Server={server},{port};Database={database};UID={user};Authentication={authentication};Encrypt=yes;'
104
+ # connString = f'Driver={{ODBC Driver 17 for SQL Server}};Server={server},{port};Database={database};UID={user};Authentication={authentication};Encrypt=yes;TrustServerCertificate=no;Connection Timeout=30 '
105
105
106
106
# For service principal.
107
107
# user = os.getenv('AZURE_SQL_USER')
108
108
# password = os.getenv('AZURE_SQL_PASSWORD')
109
- # connString = f'Driver={{ODBC Driver 18 for SQL Server}};Server={server},{port};Database={database};UID={user};PWD={password};Authentication={authentication};Encrypt=yes;'
109
+ # connString = f'Driver={{ODBC Driver 18 for SQL Server}};Server=tcp: {server},{port};Database={database};UID={user};PWD={password};Authentication={authentication};Encrypt=yes;TrustServerCertificate=no;Connection Timeout=30 '
110
110
111
111
conn = pyodbc.connect(connString)
112
112
` ` `
@@ -133,7 +133,7 @@ Update your application following the tutorial [Migrate a Java application to us
133
133
// port,
134
134
// database,
135
135
// authentication: {
136
- // authenticationType
136
+ // type: authenticationType
137
137
// },
138
138
// options: {
139
139
// encrypt: true
@@ -147,13 +147,11 @@ Update your application following the tutorial [Migrate a Java application to us
147
147
// port,
148
148
// database,
149
149
// authentication: {
150
- // type: authenticationType,
151
- // options: {
152
- // clientId: clientId
153
- // }
150
+ // type: authenticationType
154
151
// },
155
152
// options: {
156
- // encrypt: true
153
+ // encrypt: true,
154
+ // clientId: clientId
157
155
// }
158
156
// };
159
157
@@ -166,15 +164,13 @@ Update your application following the tutorial [Migrate a Java application to us
166
164
// port,
167
165
// database,
168
166
// authentication: {
169
- // type: authenticationType,
170
- // options: {
171
- // clientId: clientId,
172
- // clientSecret: clientSecret,
173
- // tenantId: tenantId
174
- // }
167
+ // type: authenticationType
175
168
// },
176
169
// options: {
177
- // encrypt: true
170
+ // encrypt: true,
171
+ // clientId: clientId,
172
+ // clientSecret: clientSecret,
173
+ // tenantId: tenantId
178
174
// }
179
175
// };
180
176
0 commit comments