invoke ado connection wizard at runtime C#

  • Thread starter Thread starter Guest
  • Start date Start date
You need to add references to both of these COM libraries:

Microsoft ActiveX Data Objects 2.8 Library
Microsoft OLEDB Service Component 1.0 Type Library

If you want to generate a new connectionstring:

public string NewConnectionString()
{
object _con = null;
MSDASC.DataLinks _link = new MSDASC.DataLinks();
_con = _link.PromptNew();
if (_con == null) return string.Empty;
return ((ADODB.Connection)_con).ConnectionString;
}

If you want to modify an existing connectionstring:

public void ExistingConnection(ref string connectionstring)
{
MSDASC.DataLinks _link = new MSDASC.DataLinks();
ADODB.Connection _con = new ADODB.Connection();
_con.ConnectionString = connectionstring;
if (_link.PromptEdit((object)_con))
{
connectionstring = _con.ConnectionString;
}
}
 
Thanks Stephany,

but i dont see any of the .net data providers in the data link dialog box
that pops up?
 
Perhaps I posted my question incorrectly, but i am looking to create a
connection string to a sql 2005 express database using the wizard at runtime.
Do you know how to call that one?
 
Stumbled across this by accident while I was looking for something else:

Step 1:

Add references to:

Microsoft.Data.ConnectionUI.dll
Microsoft.Data.ConnectionUI.Dialog.dll

You will need to browse for them at C:\Program Files\Microsoft Visual
Studio 8\Common7\IDE
(assuming that your VS2005 is installed to the default location)

Step 2:

Wherever you want to use it, execute:

Microsoft.Data.ConnectionUI.Dialog.DataConnectionDialog _dialog = new
Microsoft.Data.ConnectionUI.Dialog.DataConnectionDialog();

Microsoft.Data.ConnectionUI.Dialog.DataSource.AddStandardDataSources(_dialog);

Microsoft.Data.ConnectionUI.Dialog.DataConnectionDialog.Show(_dialog);

You will need to have a play with it to find out how to use it because I
have no further information than that.
 
At the time, all I was posting was some information that I stumbled across.

Having now tried it, I find that:

A reference to Microsoft.Data.ConnectionUI.dll is not necessary - only a
reference to Microsoft.Data.ConnectionUI.Dialog.dll is required.

The namespace in Microsoft.Data.ConnectionUI.Dialog.dll is actually
Microsoft.Data.ConnectionUI rather than Microsoft.Data.ConnectionUI.Dialog
so amend the 3 lines of code accordingly.

Microsoft.Data.ConnectionUI.DataConnectionDialog _dialog = new
Microsoft.Data.ConnectionUI.DataConnectionDialog();

Microsoft.Data.ConnectionUI.DataSource.AddStandardDataSources(_dialog);

Microsoft.Data.ConnectionUI.DataConnectionDialog.Show(_dialog);

I found that by simply opening the object browser in the IDE and having a
look at the namespaces exposed by the Microsoft.Data.ConnectionUI.Dialog
reference.

I have no need to use this dialog (as yet) and therfore have no need or
inclination to research this further, so you on your own from here.
 
Back
Top