@@ -354,6 +354,7 @@ SQLRETURN SQLDriverConnectW(SQLHDBC conn, SQLHWND windowHandle,
354
354
// spec https://github.com/apache/arrow/issues/46560
355
355
356
356
using driver::odbcabstraction::Connection;
357
+ using driver::odbcabstraction::DriverException;
357
358
using ODBC::ODBCConnection;
358
359
359
360
return ODBCConnection::ExecuteWithDiagnostics (conn, SQL_ERROR, [=]() {
@@ -369,16 +370,37 @@ SQLRETURN SQLDriverConnectW(SQLHDBC conn, SQLHWND windowHandle,
369
370
// TODO: Implement SQL_DRIVER_COMPLETE_REQUIRED in SQLDriverConnectW according to the
370
371
// spec https://github.com/apache/arrow/issues/46448
371
372
#if defined _WIN32 || defined _WIN64
372
- if (driverCompletion == SQL_DRIVER_PROMPT ||
373
- ((driverCompletion == SQL_DRIVER_COMPLETE ||
374
- driverCompletion == SQL_DRIVER_COMPLETE_REQUIRED) &&
375
- !missing_properties.empty ())) {
376
- // TODO: implement driverCompletion behavior to display connection window.
373
+ // Attempt connection once, if connection failed due to missing properties,
374
+ // load the DSN window according to driverCompletion
375
+
376
+ driver::flight_sql::config::Configuration config;
377
+ if (driverCompletion == SQL_DRIVER_PROMPT) {
378
+ DisplayConnectionWindow (windowHandle, config, properties);
379
+ connection->connect (dsn, properties, missing_properties);
380
+ } else if (driverCompletion == SQL_DRIVER_COMPLETE ||
381
+ driverCompletion == SQL_DRIVER_COMPLETE_REQUIRED) {
382
+ try {
383
+ connection->connect (dsn, properties, missing_properties);
384
+ } catch (DriverException& ex) {
385
+ // If first connection fails due to missing attributes, load
386
+ // the DSN window and try to connect again
387
+ if (!missing_properties.empty ()) {
388
+ missing_properties.clear ();
389
+
390
+ DisplayConnectionWindow (windowHandle, config, properties);
391
+ connection->connect (dsn, properties, missing_properties);
392
+ } else {
393
+ throw ex;
394
+ }
395
+ }
396
+ } else {
397
+ // Default case: attempt connection without showing DSN window
398
+ connection->connect (dsn, properties, missing_properties);
377
399
}
378
- #endif
379
-
400
+ #else
401
+ // Attempt connection without loading DSN window on macOS/Linux
380
402
connection->connect (dsn, properties, missing_properties);
381
-
403
+ # endif
382
404
// Copy connection string to outConnectionString after connection attempt
383
405
return ODBC::GetStringAttribute (true , connection_string, true , outConnectionString,
384
406
outConnectionStringBufferLen, outConnectionStringLen,
0 commit comments