arjun
arjun

Reputation: 645

ODBC Data source name

I want to create a winform which can display ODBC DSNs from the system(only this part has been done already). The user select one of it and create tables on the selected DSN. Before creating tables i need to test the DSN with a test button to show it is working. How do i get the connection string of the DSN so that i can test it and run table extracts.how do we get the provider name and other connection string property from dsn.

Upvotes: 1

Views: 3807

Answers (2)

Jeremy Thompson
Jeremy Thompson

Reputation: 65742

You get the connection string of the DSN from the Registry, see here: http://support.microsoft.com/kb/165866

HKEY_LOCAL_MACHINE\Software\ODBC..

Upvotes: 1

egrunin
egrunin

Reputation: 25083

The connection string you need is just the DSN + username + password.

using OdbcConnection conn = new OdbcConnection(
    string.Format("DSN={0};Uid={1};Pwd={2}", theDSN, theUsername, thePassword)
    )
{
    try
    {
        conn.Open();
        conn.Close();
        /* success */
    }
    catch (Exception e)
    {
        /* failure */
    }
}

(not tested)

Upvotes: 0

Related Questions