views:

402

answers:

5

Is there a way to display the connection properties dialog for connection string browsing(for database) in run time?

As I want the user to be able to connect to various database using the GUI. The same one as we get in visual studio connection properties dialog.

Thanks in Advance

http://www.freeimagehosting.net/uploads/c59e853019.jpg

+1  A: 

I don't know if there exists a 'predefined' form for it, but, you could offcourse create your own form, and use one the DbConnectionStringBuilder classes (SqlConnectionStringBuilder, OracleConnectionStringBuilder, OleDbConnectionStringBuilder) to create the connectionstring from the parameters the user entered on your custom created form.

Frederik Gheysels
@Frederik Thanks but I believe that .net has provide the dialog .We are Just not being able to find it!
Thunder
I assume the issue isnt just entering the details, but the MS dialog provides lookups, connection tests and (hopefully) exception handling!
Russell
+3  A: 

It's quite old, but there's this article - might have some inspiration for you.

Unsliced
Here's another link that talks about the same thing: http://www.mztools.com/articles/2007/MZ2007011.aspx
Gabriel McAdams
A: 

You can also use Universal Data Link Files

http://msdn.microsoft.com/en-us/library/e38h511e%28VS.71%29.aspx

Work with XP but I never tried it in Vista or Seven

Davide
+1  A: 

Look for this article explaining exactly what are you looking for. What she say is the following:

  1. You will need to add a couple references to your project:

    • OLE DB Service Component 1.0 Type Library
    • Microsoft ActiveX Data Objects 2.x Library
  2. Use the following code:

    using MSDASC;
    using ADODB;
    
    
    private string BuildConnectionString()
    {
         string strConnString = "";
         object _con = null;
         MSDASC.DataLinks _link = new MSDASC.DataLinks();
         _con = _link.PromptNew();
         if (_con == null) return string.Empty;
         strConnString = ((ADODB.Connection)_con).ConnectionString;
         return strConnString;
    }
    

Note: The original information was taken from here.

FerranB
+2  A: 

I was looking for exactly that, and it appears that Microsoft has published the source for the Visual Studio connection dialog, so that it can be used outside VS :

http://code.msdn.microsoft.com/Connection

I just tried it, it works fine :)

Thomas Levesque