Windows Develop Bookmark and Share   
 index > Windows Forms Designer > How to get all exsits connectionstrings at design time
 

How to get all exsits connectionstrings at design time

Hi,gus,
I'm developing a custom component designer,by this designer,user can configuration a data source,the UI just like the "DataSource configuration Wizard" in IDE.
but what I only need is the data table scheme the user selected,I do not want it add a DataSet(*.xsd) file to my project.

In fact,I can call a "Datasource Configuration Wizard" by DataSourceProviderService.InvokeAddNewDataSource() Method,but this will add a excrescent *.xsd file to my project.
And I can alsocall Microsoft.Data.ConnectionUI.Dialog.DataConnectionDialog,but,in this case,the user can not select an existed connectionstring in app.config.
So I want implement this wizard bymyself,but I don't know how retrive the existed connectionstrings in project app.config.
I tried the ConfigurationManager.AppSettings["ConnectonString"],but it seem to retrive from Machine.config.

I use reflector to see the source code of DataGridView control,and I monitor the value of
DataSourceProviderService by following code:

DataSourceProviderService dspSvc = (DataSourceProviderService)this.Component.Site.GetService(typeof(DataSourceProviderService));

Type tp=dspSvc.GetType();
and I found the exactly type of dspSve is and VSDDataSourceProviderService,its code like bellow:

internal class VSDDataSourceProviderService : DataSourceProviderService
{
    // Fields
    private List<GenericObjectDataSource> wsDataSourcesAdded;

    // Methods
    public VSDDataSourceProviderService();
    public override object AddDataSourceInstance(IDesignerHost host, DataSourceDescriptor dsd);
    private void DsStorage_DataSourceChanged(object sender, GenericObjectDataSourceStorage.ChangedEventArgs e);
    public override DataSourceGroupCollection GetDataSources();
    public override DataSourceGroup InvokeAddNewDataSource(IWin32Window parentWindow, FormStartPosition startPosition);
    public override bool InvokeConfigureDataSource(IWin32Window parentWindow, FormStartPosition startPosition, DataSourceDescriptor dsd);
    public override void NotifyDataSourceComponentAdded(object dataSourceComponent);

    // Properties
    public override bool SupportsAddNewDataSource { get; }
    public override bool SupportsConfigureDataSource { get; }
}
The source code of its InvokeAddNewDataSourcemethod like bellow:

public override DataSourceGroup InvokeAddNewDataSource(IWin32Window parentWindow, FormStartPosition startPosition)
{
    IServiceProvider serviceProvider = ProviderServiceHelper.GetServiceProvider();
    Project currentProject = ProjectItemUtil.GetCurrentProject();
    if (currentProject != null)
    {
         //bla bla bla
     }
}
All of these classes,methods are internal or sealed,I can't invoke them.How can I implement the function? Is my direction wrong?

What's the exactly solution?
汪汪已存圠 Monday, August 03, 2009 2:08 PM
I can only say this:

The settings designer sets up connection strings with the following attribute:

[global::System.Configuration.SpecialSettingAttribute(global::System.Configuration.SpecialSetting.ConnectionString)]

So, what you may need to do is enumerate classes that derive from ApplicationSettingsBase or SettingsBase and then enumerate the properties. If a property of type string also has the above attribute, then it is a connection string.
MCP
webJose  Friday, September 04, 2009 11:57 PM

You can use google to search for other answers

Custom Search

More Threads

• Looking for a Toolbox component that has two lists, with items moving to and from
• Clickable Image button in Windows forms
• add a form to a panel
• UserControl Designer mode failure?
• Missing SQL Server dll: Microsoft.SqlServer.Types
• unable to load designer....
• I need the CheckBox portion of the CheckBox control to be smaller, say 2/3 the size - How can I do that
• hi pls help me to limit my textbox as only integer 8 digit not less then 8
• Button inside multiline TextBox in VB?
• Details regarding UndoEngine Class in .NET