@@ -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,36 @@ 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
+ // Load the DSN window according to driverCompletion
374
+
375
+ driver::flight_sql::config::Configuration config;
376
+ if (driverCompletion == SQL_DRIVER_PROMPT) {
377
+ DisplayConnectionWindow (windowHandle, config, properties);
378
+ connection->connect (dsn, properties, missing_properties);
379
+ } else if (driverCompletion == SQL_DRIVER_COMPLETE ||
380
+ driverCompletion == SQL_DRIVER_COMPLETE_REQUIRED) {
381
+ try {
382
+ connection->connect (dsn, properties, missing_properties);
383
+ } catch (DriverException& ex) {
384
+ // If first connection fails due to missing attributes, load
385
+ // the DSN window and try to connect again
386
+ if (!missing_properties.empty ()) {
387
+ missing_properties.clear ();
388
+
389
+ DisplayConnectionWindow (windowHandle, config, properties);
390
+ connection->connect (dsn, properties, missing_properties);
391
+ } else {
392
+ throw ex;
393
+ }
394
+ }
395
+ } else {
396
+ // Default case: attempt connection without showing DSN window
397
+ connection->connect (dsn, properties, missing_properties);
377
398
}
378
- #endif
379
-
399
+ #else
400
+ // Attempt connection without loading DSN window on macOS/Linux
380
401
connection->connect (dsn, properties, missing_properties);
381
-
402
+ # endif
382
403
// Copy connection string to outConnectionString after connection attempt
383
404
return ODBC::GetStringAttribute (true , connection_string, true , outConnectionString,
384
405
outConnectionStringBufferLen, outConnectionStringLen,
0 commit comments