473,387 Members | 1,899 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Using Multiple Datasources

I have an application that can either connect to an access database or
a SQL Server database. I have 2 assemblies both implement the same
interface for describing the data access methods for the application.
One assembly is specific to use the Access database using the OLEDB
provider, the other is specific to SQL Server using the SQLServer
provider. I want to be able to use the SQL server provider for the SQL
server assembly.
My original thought was to have 2 compiled versions of the app, one for
Access and one for SQL Server. I believe there is a better way to do
this using the app.config file but am not sure exactly how to go about
it.

Any thoughts?

Thanks in advance

Jeff D.

Dec 11 '06 #1
2 1899

If you have the same interface, then you've done most of the work.

Go to:
12/1/2005
Understanding the Simple Factory Pattern

http://sholliday.spaces.live.com/blog/
I would use "reflection", or the "key" method. And create a Factory class.
( A factory class is a class that creates other classes)
You could have the key value in your config file.

Then you'd need a factory

public class TalkToDatabaseFactory
{

public static IMyDatabaseAccessInterface GetMyDatabaseAccessInterface ()
{
string key = "Access"; // read this from web.config file

switch (key.ToUpper())
{
case "ACCESS":
return new MyDatabaseAccess();
case "SQLSERVER":
return new SqlServerMyDatabaseAccess();

default:
throw new ArgumentException("The AnimalFactory was given a Bad Key");

}
}
}

<je**@derouse.comwrote in message
news:11**********************@79g2000cws.googlegro ups.com...
I have an application that can either connect to an access database or
a SQL Server database. I have 2 assemblies both implement the same
interface (IMyDatabaseAccessInterface for describing the data access
methods for the application.
One assembly is specific to use the Access database using the OLEDB
provider, the other is specific to SQL Server using the SQLServer
provider. I want to be able to use the SQL server provider for the SQL
server assembly.
My original thought was to have 2 compiled versions of the app, one for
Access and one for SQL Server. I believe there is a better way to do
this using the app.config file but am not sure exactly how to go about
it.

Any thoughts?

Thanks in advance

Jeff D.

Dec 11 '06 #2
On 11 Dec 2006 11:16:02 -0800, je**@derouse.com wrote:
>I have an application that can either connect to an access database or
a SQL Server database. I have 2 assemblies both implement the same
interface for describing the data access methods for the application.
One assembly is specific to use the Access database using the OLEDB
provider, the other is specific to SQL Server using the SQLServer
provider. I want to be able to use the SQL server provider for the SQL
server assembly.
My original thought was to have 2 compiled versions of the app, one for
Access and one for SQL Server. I believe there is a better way to do
this using the app.config file but am not sure exactly how to go about
it.

Any thoughts?
Two data sources and a common interface sounds like you might want to
use the provider model. In the app.config one of the providers can be
set as the default depending upon the desired data source.

regards
A.G.
Dec 11 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Don | last post by:
I have a set of modules that all have the same interface, and package name: _______________________________ package dataSourcePackage; # Initialize global variables $hashOne{'uniquekey1'} =...
3
by: lee_mcknight | last post by:
I am using Crystal Enterprise V9. I have a report that needs to have multiple datasets as the datasource(s) on a single subreport (some common lookup data I need to join to is stored in a seperate...
0
by: Greg | last post by:
Anyone having issues with their object datasources appearing and vanishing from the datasource browser? I create an object for binding as a datasource in my App_Code folder, compile my web...
1
by: Nick | last post by:
I am working on a website for a client and one of their requirements was to have a mailing list. I decided to XSLT to transform "templates" to HTML so that editing was very easy and less time...
1
by: Magnus | last post by:
I have a set of typed datasets that are tied to a database on a mssql2005 server. They are naturally displayed and available in the DataSources window. Now I want to rename the database, but when I...
3
by: jobs | last post by:
I've got a gridview that does not have a datasourceid assigned in the markup. I'd like to switch between two datasources in the codebehind. when I do switch, I first reset the the...
1
by: Larry Bud | last post by:
I have a stored procedure that returns statistics based on the parameter passed to it. I would like to have a table with 4 columns, (and about 20 rows which is what is returned from the SP). Each...
19
by: cpnet | last post by:
I'm using VS2005, C#, ASP.NET 2.0. I'm trying to create a report using SQL Reporting Services (to be used in local mode so I don't have to deal with SQL Server). When I create a new report in my...
0
by: c0dergirl | last post by:
This c# program allows you to select multiple items from a listbox. For each selected item, a worksheet is created in the workbook with some information. Right now I create a chart that plots some...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.