Connecting a UI.Dialog for a C # installation project

enter image description here

I add the Microsoft.Data.ConnectionUI.Dialog.dll and Microsoft.Data.ConnectionUI.dll DLL files to my project and use this code:

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

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

        if (Microsoft.Data.ConnectionUI.DataConnectionDialog.Show(dcd) == System.Windows.Forms.DialogResult.OK)
        {
            //
        }
        else
        {
            //
        }

When I use this in regular Windows applications, everything looks fine (the standard VS dataconnection dialog with the Advanced button is displayed). When I use it in SETUP PROJECT, it shows only the advanced dialog box, and the OK button is disabled. Users can check the connection, but cannot click OK.

Does anyone know why this is not working?

+5
source share
3 answers

The buttons are on / off depending on the settings.

: http://erikej.blogspot.com.au/2010/04/using-adonet-data-connection-dialog-in.html " " , , , "".

DataSource, OK . Data Connection Dialog Source Code, : http://archive.msdn.microsoft.com/Connection/Release/ProjectReleases.aspx?ReleaseId=3863

Micrsost.Data.ConnectionUI.Dialog DataConnectionDialog.cs, , :

private void ConfigureAcceptButton(object sender, EventArgs e)
{
try
{
acceptButton.Enabled = (ConnectionProperties != null) ? ConnectionProperties.IsComplete : false;
}
catch
{
acceptButton.Enabled = true;
}
}

ConnectionProperties PropertyChange:

properties.PropertyChanged += new EventHandler(ConfigureAcceptButton);

OK, ConnectionProperties.IsComplete.

+2

, , DataConnectionDialog PowerPoint.

, SqlConnectionUIControl STA. , .

, .

private void dataSourceSelectionButton_Click(object sender, EventArgs e)
{
  Thread browseThread = new Thread(promptForConnectionString);
  browseThread.TrySetApartmentState(ApartmentState.STA);
  browseThread.Start();  
}

.

public string ConnectionString { get; set; }

private void promptForDataConnection()
{
  DataConnectionDialog dataConnection = new DataConnectionDialog();
  DataConnectionConfiguration connectionConfiguration = new DataConnectionConfiguration(null);
  connectionConfiguration.LoadConfiguration(dataConnection);

  if (DataConnectionDialog.Show(dataConnection) == DialogResult.OK)
  {
    connectionConfiguration.SaveConfiguration(dataConnection);

    this.ConnectionString = dataConnection.ConnectionString;
  }
}

, DataConnectionDialog Source.

+1

I cannot solve this problem by running VS2008 as administrator. I solve this problem by disabling the option "Enabled Visual Studio Hosting" in the Winform project.

0
source

All Articles