Add a COM reference to:
Microsoft OLE DB Service Component 1.0 Type Library
Microsoft ActiveX Data Objects 2.7 // any 2.5 or higher version is fine
You can then write code like:
//
// Prompt for a totally new connection string
//
private void button1_Click(object sender, EventArgs e)
{
bool Cancelled = false;
string ConnectionString = string.Empty;
MSDASC.DataLinks d = new MSDASC.DataLinks();
d.hWnd = (int)this.Handle;
ADODB._Connection c = (ADODB._Connection)d.PromptNew();
if (c == null)
Cancelled = true;
else
{
Cancelled = false;
ConnectionString = c.ConnectionString;
}
}
//
// Edit a connection string
//
private void button2_Click(object sender, EventArgs e)
{
bool Saved = false;
string ConnectionString = "Provider=SQLOLEDB.1;Integrated
Security=SSPI;Persist Security Info=False;User ID=sa;Initial
Catalog=Northwind;Data Source=.";
MSDASC.DataLinks d = new MSDASC.DataLinks();
d.hWnd = (int)this.Handle;
object c = new ADODB.Connection();
((ADODB._Connection)c).ConnectionString = ConnectionString;
Saved = d.PromptEdit(ref c);
if (Saved)
{
ConnectionString = ((ADODB._Connection)c).
ConnectionString;
}
}

Leave a comment