Monday, May 24, 2010

Editing an existing connectionstring with the DataConnectionDialog at runtime

Editing an existing connectionstring with the DataConnectionDialog at runtime: "Visual Studio Developer Center

Suggestions

Close
Sign in
United States (English)
Australia (English)Brasil (Português)Česká republika (Čeština)Danmark (Dansk)Deutschland (Deutsch)España (Español)France (Français)Indonesia (Bahasa)Italia (Italiano)România (Română)Россия (Русский)대한민국 (한국어)中华人民共和国 (中文)台灣 (中文)日本 (日本語)香港特別行政區 (中文)

HomeGetting StartedLibraryLearnDownloadsSolutionsGallerySupportForums
Visual Studio Developer Center > Visual Studio Forums > Visual Studio Extensibility > Editing an existing connectionstring with the DataConnectionDialog at runtime
Ask a questionAsk a question
Search Forums:

* Search Visual Studio Extensibility Forum Search Visual Studio Extensibility Forum
* Search All Visual Studio Forums Search All Visual Studio Forums
* Search All MSDN Forums Search All MSDN Forums


AnswerEditing an existing connectionstring with the DataConnectionDialog at runtime

*
Wednesday, May 03, 2006 1:46 AMLanceM Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals

Sign In to Vote
0
Sign In to Vote

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.
o ReplyReply
o QuoteQuote


Answers

*
Wednesday, May 31, 2006 6:57 PMMilind Lele - MSFT Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
Answer
Sign In to Vote
0
Sign In to Vote

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


o ReplyReply
o QuoteQuote

*
Tuesday, June 06, 2006 12:00 AMLanceM Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
Answer
Sign In to Vote
0
Sign In to Vote

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
o ReplyReply
o QuoteQuote

*
Wednesday, March 05, 2008 2:00 PMCarlos Quintero - MVPMVP, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
Answer
Sign In to Vote
0
Sign In to Vote

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...
o ReplyReply
o QuoteQuote


All Replies

*
Thursday, May 11, 2006 12:09 AMMilind Lele - MSFT Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals

Sign In to Vote
0
Sign In to Vote

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
o ReplyReply
o QuoteQuote

*
Friday, May 19, 2006 12:02 AMLanceM Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals

Sign In to Vote
0
Sign In to Vote

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
o ReplyReply
o QuoteQuote

*
Wednesday, May 31, 2006 6:57 PMMilind Lele - MSFT Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
Answer
Sign In to Vote
0
Sign In to Vote

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


o ReplyReply
o QuoteQuote

*
Wednesday, May 31, 2006 11:45 PMLanceM Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals

Sign In to Vote
0
Sign In to Vote

Hi Milind,

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

Lance
o ReplyReply
o QuoteQuote

*
Monday, June 05, 2006 6:02 AMLanceM Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals

Sign In to Vote
0
Sign In to Vote

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
o ReplyReply
o QuoteQuote

*
Monday, June 05, 2006 7:24 PMMilind Lele - MSFT Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals

Sign In to Vote
0
Sign In to Vote

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.
o ReplyReply
o QuoteQuote

*
Tuesday, June 06, 2006 12:00 AMLanceM Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
Answer
Sign In to Vote
0
Sign In to Vote

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
o ReplyReply
o QuoteQuote

*
Friday, July 28, 2006 6:53 PMThe_Drewster Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals

Sign In to Vote
0
Sign In to Vote

Hi

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

*
Sunday, July 30, 2006 11:43 PMLanceM Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals

Sign In to Vote
0
Sign In to Vote

To return the results of the dialog (i.e. the connectionstring) to a text box do the following:

TextBox1.text = dcd.ConnectionString;
o ReplyReply
o QuoteQuote

*
Monday, July 31, 2006 8:04 AMThe_Drewster Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals

Sign In to Vote
0
Sign In to Vote



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.
o ReplyReply
o QuoteQuote

*
Tuesday, August 08, 2006 9:15 PMCraig Z Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals

Sign In to Vote
0
Sign In to Vote



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?
o ReplyReply
o QuoteQuote

*
Tuesday, August 08, 2006 9:19 PMThe_Drewster Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals

Sign In to Vote
0
Sign In to Vote

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.
o ReplyReply
o QuoteQuote

*
Wednesday, August 09, 2006 4:28 PMCraig Z Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals

Sign In to Vote
0
Sign In to Vote



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
o ReplyReply
o QuoteQuote

*
Wednesday, March 05, 2008 12:02 PMLaughing John Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals

Sign In to Vote
0
Sign In to Vote
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!!!

o ReplyReply
o QuoteQuote

*
Wednesday, March 05, 2008 2:00 PMCarlos Quintero - MVPMVP, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
Answer
Sign In to Vote
0
Sign In to Vote

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...
o ReplyReply
o QuoteQuote

*
Monday, March 10, 2008 2:48 PMLaughing John Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals

Sign In to Vote
0
Sign In to Vote
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.
o ReplyReply
o QuoteQuote

*
Tuesday, February 02, 2010 6:13 AMYaohaiZheng Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
Proposed Answer
Sign In to Vote
0
Sign In to Vote
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
o Proposed As Answer byLaughing John Wednesday, May 12, 2010 12:25 PM
o
o ReplyReply
o QuoteQuote


Need Help with Forums? (FAQ)
My Forum Links

* Sign In To Forums
* Forums Home
* Browse Forums Users

Statistics

* Started: 5/3/2006
* Last Reply: 2/2/2010
* Helpful Votes: 0
* Replies: 17
* Views: 4,816


© 2010 Microsoft Corporation. All rights reserved.
Terms of Use|Trademarks|Privacy Statement|Contact Us|Manage Your Profile


- Sent using Google Toolbar"

No comments:

Post a Comment