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