How to show the Windows Standard Data Sources (ODBC) Dialog Box
Is there an easy way to display the standard Windows data sources dialog from a winforms application?
I would like to show it to the user and pick up the dsn system, or create a new one and return the datasource name. I have not found any references to existing wrappers in .net, so I guess I can use the win API for this. Any existing solution or piece of code would be appreciated.
source to share
It seems impossible to get the selected datasource name from this dialog. Here is the winapi function that can be used to invoke this dialog ( link ):
BOOL SQLManageDataSources(HWND hwnd);
And here's a snippet:
[DllImport("ODBCCP32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
private static extern bool SQLManageDataSources(IntPtr hwnd);
private void ShowDataSourceDialog()
{
SQLManageDataSources(Handle);
}
The hwnd argument is the parent window handle. The dialog is displayed only for a valid window handle. While I cannot select a data source this way, I can at least provide the ability to add, modify, or delete data sources using the existing standard tool. Otherwise, I need to create a custom.
source to share
Maybe you can create your own window where user can insert / select DSN.
There are several examples on how to manually insert new DSNs and list the ones that are already configured on the machine:
Check system DSN and create system DSN if NOT Existing (ODBC driver for iSeries Access)
Add DSNs dynamically
List ODBC drivers from .NET
source to share