tags:

views:

31

answers:

1

Given a connection object (or series of them), does anyone know of a way to backtrack and get the provider name?

I'm trying to create a generic dataset generator that someone could load up with n DbCommand instances populate the dataset without requiring any further information.

Theoretically, as a command requires a connection object, that's all the information one should need to create this tool.

Given that I'm populating tables in a dataset, I figured the simplest way would be using a DataAdapter. The only problem is that to generate a generic DataAdapter, I seem to have to go through the provider factory which requires a provider string - which I don't have.

Also, given that the provider for each command could potentially be different (i.e. commands across numerous databases), does anyone have any suggestions that would keep this simple?

I'd like not to have to require the user to provide the provider string for each command object if I can avoid it. This way the user can just pass a param array of DbCommands and I can take it from there.

Any suggestions would be extremely useful. Thanks.

+1  A: 

There's DbConnection.DbProviderFactory property which does exactly this; the only problem is that it is protected. Note that this still means that it's published API, so using Reflection to access it shouldn't be prone to versioning breakage, though it will require appropriate permissions for your code to circumvent visibility checks.

Pavel Minaev
Works like a charm - thanks for pointing me in the right direction, I appreciate the swift response! :)
BenAlabaster