locked
DataConnectionDialog and Oracle via OleDB RRS feed

  • Question

  • Hi,

    I'm currently writing a UITypeEditor that uses the DataConnectionDialog. All works like a charm, however I'm storing the results of the dialog to initialize it with theses if the user chooses to revisit the dialog to change her settings.

    Whenever I try to initialize the dialog for an Oracle connection via OleDB like so (you can easily paste this in a new blank C# problem to reproduce):

    DataConnectionDialog dlg = new DataConnectionDialog();
    
    DataSource.AddStandardDataSources(dlg);
    
    dlg.SelectedDataSource = DataSource.OracleDataSource;
    
    dlg.SelectedDataProvider = DataProvider.OleDBDataProvider;
    
    dlg.ConnectionString = "Provider=MSDAORA;Data Source=ewe;User ID=ewe";
    
    
    
    

    I end up with an exception (tested with VS2008, Win7 x64)

    System.InvalidOperationException was unhandled
      Message="The selected data source has no association with this data provider."
      Source="Microsoft.Data.ConnectionUI.Dialog"

    Reflector tells me the only source is in the  SetSelectedDataProvider(DataSource dataSource, DataProvider value, bool noSingleItemCheck) routine of the dialog and happens once the check for dataSource.Providers.Contains(value) fails. However, sure enough the OleDB provider is contained in the Oracle DataSource's provider collection and so I'm hosed. Can anyone check this or - even better - come up with a solution?

    Thanks,

    John

    Thursday, April 1, 2010 7:14 AM

Answers

  • Hello John,

    I have reproduced the problem and it is a problem of instances, so the fix is to supply the exact instance from the SelectedDataSource.Providers collection, not another equivalent instance:

             objDataConnectionDialog = new DataConnectionDialog();

             DataSource.AddStandardDataSources(objDataConnectionDialog);

             objDataConnectionDialog.SelectedDataSource = DataSource.OracleDataSource;

             foreach (DataProvider objDataProvider in objDataConnectionDialog.SelectedDataSource.Providers)
             {
                if (objDataProvider.Name == "System.Data.OleDb")
                {
                   objDataConnectionDialog.SelectedDataProvider = objDataProvider;
                   break;
                }

             }

     

    I have updated my article to fix this problem:

    HOWTO: Using the Choose Data Source dialog of Visual Studio 2005 from your own code
    http://www.mztools.com/articles/2007/MZ2007011.aspx

     


    MZ-Tools: Productivity add-ins for Visual Studio: http://www.mztools.com. My blog about developing add-ins: http://msmvps.com/blogs/carlosq/
    Friday, April 2, 2010 12:48 PM

All replies

  • Hello John,

    I have reproduced the problem and it is a problem of instances, so the fix is to supply the exact instance from the SelectedDataSource.Providers collection, not another equivalent instance:

             objDataConnectionDialog = new DataConnectionDialog();

             DataSource.AddStandardDataSources(objDataConnectionDialog);

             objDataConnectionDialog.SelectedDataSource = DataSource.OracleDataSource;

             foreach (DataProvider objDataProvider in objDataConnectionDialog.SelectedDataSource.Providers)
             {
                if (objDataProvider.Name == "System.Data.OleDb")
                {
                   objDataConnectionDialog.SelectedDataProvider = objDataProvider;
                   break;
                }

             }

     

    I have updated my article to fix this problem:

    HOWTO: Using the Choose Data Source dialog of Visual Studio 2005 from your own code
    http://www.mztools.com/articles/2007/MZ2007011.aspx

     


    MZ-Tools: Productivity add-ins for Visual Studio: http://www.mztools.com. My blog about developing add-ins: http://msmvps.com/blogs/carlosq/
    Friday, April 2, 2010 12:48 PM
  • Hi Carlos,

    Thanks very much for the reply - will try it right after easter. Funny thing is the "normal" approach works for all other combinations. Well, I won't care as long as I have a solution. Thanks again!

    Jochen

    Friday, April 2, 2010 7:21 PM
  • Works indeed - thanks a lot. Would you replace the other - currently working - assignments to SelectedDataProvider with the same logic?
    Saturday, April 3, 2010 8:51 AM
  • Hello Jochen,

    Which other assignments to SelectedDataProvider are you referring to?


    MZ-Tools: Productivity add-ins for Visual Studio: http://www.mztools.com. My blog about developing add-ins: http://msmvps.com/blogs/carlosq/
    Monday, April 5, 2010 8:01 AM
  • Hi Carlos,

    if you use any other combination of DataSource and Provider, you don't have to reference the provider collection from the SelectedDataSource but can use the static properties of the DataProvider class directly as I was trying to do originally. The effect I was having only seems to happen in this specific combination (Oracle/OleDb). However, as I could not find the reason for this happening I was wondering if your way would be more secure for all other cases, too.

    Jochen

    Tuesday, April 6, 2010 6:11 AM
  • I am not sure because I was a bit surprised with the error too.

    I would check with all providers and datasources in each VS version (2005, 2008 and 2010) and do whatever must be done to make it work in each case.


    MZ-Tools: Productivity add-ins for Visual Studio: http://www.mztools.com. My blog about developing add-ins: http://msmvps.com/blogs/carlosq/
    Tuesday, April 6, 2010 9:45 AM
  • Hi Carlos,

     

    I got this figured out - it's actually  a design flaw in the dialog's initialization logic. During initialization, the static getter for DataProvider.OleDBDataProvider is called - first for the SQL data source. However, this in turn calls to

    dataSourceDescriptions.Add(DataSource.OracleDataSource.Name, Microsoft.Data.ConnectionUI.SR.GetString("DataProvider_OleDB_OracleDataSource_Description"));

    which results in a stack trace like this:

    >    Microsoft.Data.ConnectionUI.Dialog.dll!Microsoft.Data.ConnectionUI.DataProvider.OleDBDataProvider.get() Line 176    C#
         Microsoft.Data.ConnectionUI.Dialog.dll!Microsoft.Data.ConnectionUI.DataSource.OracleDataSource.get() Line 146 + 0x2e bytes    C#
         Microsoft.Data.ConnectionUI.Dialog.dll!Microsoft.Data.ConnectionUI.DataProvider.OleDBDataProvider.get() Line 178 + 0x12 bytes    C#
         Microsoft.Data.ConnectionUI.Dialog.dll!Microsoft.Data.ConnectionUI.DataSource.SqlDataSource.get() Line 169 + 0x2e bytes    C#

    Thus, the top frame leaves the static (!) getter with a different value for the OleDBDataProvider value than the lower, as the value for the provider is not initialized before leaving the getter. So you can never rely on the static providers being the same over the different data sources. This should be escalated to Microsoft, although I will implement the workaround as pointed out by you.

    Cheers,

    J.

    Wednesday, April 7, 2010 4:02 AM
  • I have escalated it to Microsoft, it also happens in VS 2010/.NET 4.0:

    https://connect.microsoft.com/VisualStudio/feedback/details/549584/the-selected-data-source-has-no-association-with-this-data-provider-error-using-oledb-provider#details


    MZ-Tools: Productivity add-ins for Visual Studio: http://www.mztools.com. My blog about developing add-ins: http://msmvps.com/blogs/carlosq/
    Thursday, April 8, 2010 11:34 AM