Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to do multiple data sources?
Message
De
19/04/2010 16:55:27
Timothy Bryan
Sharpline Consultants
Conroe, Texas, États-Unis
 
 
À
19/04/2010 15:31:20
Guy Pardoe
Pardoe Development Corporation
Peterborough, New Hampshire, États-Unis
Information générale
Forum:
ASP.NET
Catégorie:
The Mere Mortals .NET Framework
Divers
Thread ID:
01460976
Message ID:
01460991
Vues:
33
>Hi,
>
>I need clarification on the steps necessary for different business objects in a MM.NET application for accessing different datasources.
>
>I'm building an application whose primary data source is a Microsoft SQL Server database. No problem there. I've got some business objects already defined and working that can read and write to the SQL Server database.
>
>But I've got some circumstances where I'm reading some data from other applications (i.e., other data sources). In one example, I need a business object (yet to be defined) that will access data in a totally separate SQL Server database. In another case, I need a business object (to be defined) that will read from an existing VFP database (actually free tables, not contained within a DBC).
>
>I think I'm supposed to add multiple databasekey entries in the app.config file, one for each database I need to access. Is that right?
>
>Then, do I need to manually set the databasekey property to an appropriate databasekey value in the class definition of the business object? I assume this must be the case because if I don't do this, the business object would then refer to the primary database (which I do not want to happen). Am I understanding this right?
>
>I see an entry in the MM.NET help file named "Working with Multiple Data Access Objects" but I can't grasp where to put the suggested sample code, or why it would matter as long as I have already defined the database keys values for each database in the app.config file.
>
>It leads me to think I must be misunderstanding something fundamental.
>
>I'm just looking for the proper steps to follow in a best-practices kind of way.
>
>Any advice?

Hi Guy,

There are a couple of different approaches depending on the data and purpose. If the data in the different data sources is not the same data, then yes, just create another Business Object Project for connecting to a second data source/ type. Set the connection in the app.config just like in your other project for that specific data. This connection is used for the development purpose. You also need to have the database key name set in your ABusinessObject. Basically everything is identical to creating your first business object project.

Now in your web or windows application, add the new business object project. You should now have two of them. You will need to have another connection defined in your web.config or app.config of the application project so that you would have two of them; one for each business project. Also add the refrences to both business projects in your application references.

Keep in mind you will need to be careful with names to make it easier on you. For instance don't have a business object named Orders in one business project and a business object named orders in the other as well if you can avoid it. If you must do that, you can do this no problem, but you will have to deal with it specifically.

In a form where you are going to get data from both business object projects you just add a using statement for both projects and register them just like any other time.

If the data is identical in each data source than you are better off not creating two busines object projects. The sample application ships with MM has both sql data and fox data but only one business project and set of entities. In that case you can switch between the data types using datasets defined like the sample or you can do it manually.

I hope that helps
Tim
Timothy Bryan
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform