Bug #82415 Creating a DSN using SQLConfigDataSource with null window handle emits Exception
Submitted: 2 Aug 2016 17:36 Modified: 5 Sep 2016 14:06
Reporter: Nathaniel Madura Email Updates:
Status: No Feedback Impact on me:
Category:Connector / ODBC Severity:S2 (Serious)
Version:5.3.6 OS:Windows (32)
Assigned to: Assigned Account CPU Architecture:Any
Tags: SQLConfigDataSource

[2 Aug 2016 17:36] Nathaniel Madura
When calling (from a Console Application/C#)

BOOL SQLConfigDataSource(
     HWND     hwndParent,
     WORD     fRequest,
     LPCSTR   lpszDriver,
     LPCSTR   lpszAttributes);


Above documentation says passing a NULL (IntPtr.Zero) to hwndParent will suppress dialog boxes.

However, when using NULL as an argument the connector emits a System.AccessViolationException

How to repeat:
public static class Stub
private static extern bool SQLConfigDataSource(IntPtr hwndParent, int fRequest, string lpszDriver, string lpszAttributes);

       public static void CreateDataSource()
            StringBuilder sb = new StringBuilder();
            sb.AppendFormat("Database={0}", k_Database);
            sb.AppendFormat("Description={0}", k_Description);
            sb.AppendFormat("Port={0}", k_Port);
            sb.AppendFormat("Pwd={0}", k_Pwd);
            sb.AppendFormat("Server={0}", k_Server);
            sb.AppendFormat("UID={0}", k_Uid);
            bool ret = SQLConfigDataSource(handle, ODBC_ADD_USER_DSN, k_Driver, sb.ToString());


Suggested fix:
myodbc dll should be able to accept NULL as a window handle, as this is outlined as acceptable by Microsoft's api

In the mean time passing a window handle from Process.GetCurrentProcess().MainWindowHandle seems to be a viable work-around, however the client will still be presented with the mysql connector dialog box.
[2 Aug 2016 18:00] Nathaniel Madura
After further review, specifying the DNS parameter did allow NULL to function.

So the unexpected behavior may only occur when the "Attributes"/Connection string is incorrect.

it seems like the better behavior would be to return false and utilize SQLInstallerError to pass info back, rather than causing an exception with a null window handle.
[5 Aug 2016 14:06] Chiranjeevi Battula
Hello Nathaniel,

Thank you for the bug report.
Could you please provide repeatable test case (exact steps, sample project, etc. - please make it as private if you prefer) to confirm this issue at our end?

[6 Sep 2016 1:00] Bugs System
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".