locked
Editing an existing connectionstring with the DataConnectionDialog at runtime RRS feed

  • Question

  • Can anyone tell me if it is possible to edit an existing connectionstring with the DataConnectionDialog at runtime in my own winform application?  I can create a new one at runtime in my own winform application using the following code:

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

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

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

    Once I have created one, I would like to be able to use the same dialog to edit it by feeding it the existing connectionstring information (the equivalent of the PromptEdit method of the MSDASC.DataLinks object).

    Any help would be much appreciated.

    Wednesday, May 3, 2006 1:46 AM

Answers

  • Hi Lance,

    I apologize. I should have clarified.

    I said it cannot be used at run time because the assembly (Microsoft.Data.ConnectionUI.Dialog) is not licensed for redistribution.

    If, however, the assembly already exists on the machine (because VS is installed), you can indeed use it as you have described. To use it to modify an existing connection string you will need to do an equivalent of the following:

    dcd.SelectedDataSource = DataSource.SqlDataSource
    dcd.SelectedDataProvider = DataProvider.SqlDataProvider
    dcd.ConnectionString = "Data Source=myserver;Initial Catalog=Northwind;Integrated Security=True"

    Thanks.

    Milind

     

    Wednesday, May 31, 2006 6:57 PM
  • Hi Milind,

    Thanks for your quick response and help.  This worked with a minor tweak to the order of the lines of code.  Below is the code that worked:

    using Microsoft.Data.ConnectionUI;

    string strConnectionString = "Data Source=myserver;Initial Catalog=Northwind;Integrated Security=True";

    DataConnectionDialog dcd = new DataConnectionDialog();
    DataSource.AddStandardDataSources(dcd);

    dcd.SelectedDataSource = DataSource.SqlDataSource;
    dcd.SelectedDataProvider = DataProvider.SqlDataProvider;
             
    dcd.ConnectionString = strConnectionString;

    DataConnectionDialog.Show(dcd);

    Thanks again for your help,

    Lance

    Tuesday, June 6, 2006 12:00 AM
  • Even if MS allowed the redistribution of those DLLs, that only would work with the "standard" .NET data providers, namely, SQL Server, Oracle, OLEDB and ODBC. It would not work with, say, ODP.NET for Oracle, Sybase, MySQL or whatever else. See my blog post:

     

    http://msmvps.com/blogs/carlosq/archive/2008/01/16/more-on-quot-howto-using-the-choose-data-source-dialog-of-visual-studio-2005-from-your-own-code-quot.aspx

     

    So, what is really needed is a single pair of DLL that works with all registered DDEX providers (which should register outside Visual Studio), and then make then redistributable.

     

    As it should be clear now, the history of ADO.NET design-time data source dialog couldn't be worse: lack of support in VS.NET 2002/2003, and half baked support if you want to use them outside VS with ANY ADO.NET data provider which supports DDEX, not to mention the legal issue of making nothing redistributable...

    Wednesday, March 5, 2008 2:00 PM

All replies

  • Hi Lance,

    It is not possible to use the DataConnectionDialog at run time. It is meant for design time experience only.

    Thanks.

    Milind Lele
    PM, VS Pro Data

    Thursday, May 11, 2006 12:09 AM
  • Hi Milind,

    It is possible to use it at runtime, I have done it (see code in previous post).  I have managed to use it to create a connectionstring but wanted to know how to use it to edit an existing one.

    Lance

    Friday, May 19, 2006 12:02 AM
  • Hi Lance,

    I apologize. I should have clarified.

    I said it cannot be used at run time because the assembly (Microsoft.Data.ConnectionUI.Dialog) is not licensed for redistribution.

    If, however, the assembly already exists on the machine (because VS is installed), you can indeed use it as you have described. To use it to modify an existing connection string you will need to do an equivalent of the following:

    dcd.SelectedDataSource = DataSource.SqlDataSource
    dcd.SelectedDataProvider = DataProvider.SqlDataProvider
    dcd.ConnectionString = "Data Source=myserver;Initial Catalog=Northwind;Integrated Security=True"

    Thanks.

    Milind

     

    Wednesday, May 31, 2006 6:57 PM
  • Hi Milind,

    Thanks for you help.  I'll give it a try.

    Lance

    Wednesday, May 31, 2006 11:45 PM
  • Hi Milind,

    I tried the editing code you supplied and it failed because Datasource.SqlDataSource is null when you try to assign dcd.SelectedDataSource.  Other than the line creating dcd, are those three lines of code all I need?  Please let me know.

    Thanks,

    Lance

    Monday, June 5, 2006 6:02 AM
  • Indeed! Keep the rest of the code in your original post the same. All you need to do is add the lines I had posted.

    Thanks.

    Monday, June 5, 2006 7:24 PM
  • Hi Milind,

    Thanks for your quick response and help.  This worked with a minor tweak to the order of the lines of code.  Below is the code that worked:

    using Microsoft.Data.ConnectionUI;

    string strConnectionString = "Data Source=myserver;Initial Catalog=Northwind;Integrated Security=True";

    DataConnectionDialog dcd = new DataConnectionDialog();
    DataSource.AddStandardDataSources(dcd);

    dcd.SelectedDataSource = DataSource.SqlDataSource;
    dcd.SelectedDataProvider = DataProvider.SqlDataProvider;
             
    dcd.ConnectionString = strConnectionString;

    DataConnectionDialog.Show(dcd);

    Thanks again for your help,

    Lance

    Tuesday, June 6, 2006 12:00 AM
  • Hi

    How do you return the results of the dialog to say a text box?

    Friday, July 28, 2006 6:53 PM
  • To return the results of the dialog (i.e. the connectionstring) to a text box do the following:

    TextBox1.text = dcd.ConnectionString;

    Sunday, July 30, 2006 11:43 PM
  •  

    Thank you.

    I did eventually stumble across the solution after many a messing around with what intellisense offered.

    Can I ask, for an undocumented dll as this, how do you find out a solution to the question I asked without guess-timating.

    Monday, July 31, 2006 8:04 AM
  •  

    This "Microsoft.Data.ConnectionUI.Dialog.dll" is distributed freely with Visual Studio Express.  Given this information, do you believe that Microsoft would give permission to distribute the .dll if asked via the proper channels?

    Tuesday, August 8, 2006 9:15 PM
  • If you don't ask you don't get. I wouldn't know who to ask though.

    I thought I'd just put a disclaimer saying the user was responsible for first installing VS 2005 on their machine before using my app.

    Tuesday, August 8, 2006 9:19 PM
  •  

    Forget about the DataConnectionDialog and just use the DataLink UI that is distributed with MDAC.  Reference the KB article below.

    KB #310083 - HOW TO: Build a Connection String Programmatically in ADO.NET

    Wednesday, August 9, 2006 4:28 PM
  • As the knowledge base says this should only be used as a temporary measure. It is also not .Net specific and involves interop which is not ideal.

    What we need is a consistent .Net dialog to create database connections that we can all reuse in the same way we have a consistent dialog for opening files, printing etc.

    A feedback request to MS for such a beast has been created here:

    http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=291885

    Please vote!!!

    Wednesday, March 5, 2008 12:02 PM
  • Even if MS allowed the redistribution of those DLLs, that only would work with the "standard" .NET data providers, namely, SQL Server, Oracle, OLEDB and ODBC. It would not work with, say, ODP.NET for Oracle, Sybase, MySQL or whatever else. See my blog post:

     

    http://msmvps.com/blogs/carlosq/archive/2008/01/16/more-on-quot-howto-using-the-choose-data-source-dialog-of-visual-studio-2005-from-your-own-code-quot.aspx

     

    So, what is really needed is a single pair of DLL that works with all registered DDEX providers (which should register outside Visual Studio), and then make then redistributable.

     

    As it should be clear now, the history of ADO.NET design-time data source dialog couldn't be worse: lack of support in VS.NET 2002/2003, and half baked support if you want to use them outside VS with ANY ADO.NET data provider which supports DDEX, not to mention the legal issue of making nothing redistributable...

    Wednesday, March 5, 2008 2:00 PM
  • Agreed! We don't need those actual DLLs. What we need is a standard component/control that offers the same functionality preferably supplied along with visual studio. And it definitely should handle 3rd party data providers.
    Monday, March 10, 2008 2:48 PM
  • The Data Connection Dialog Source Code is just released at: http://code.msdn.microsoft.com/Connection

    You can take a look at the introduction on: http://blogs.msdn.com/vsdata/archive/2010/02/02/data-connection-dialog-source-code-is-released-on-code-gallery.aspx

    Briefly, it provides three functionalities mentioned in this discussion thread.

    · Build/Modify connection strings.

    · Customize the data connection dialog.

    · Write your own custom data providers.

    Hope this helps,


    Yaohai Zheng

    • Proposed as answer by Laughing John Wednesday, May 12, 2010 12:25 PM
    Tuesday, February 2, 2010 6:13 AM