Multiple database: SQLServer & MySQL

Posts   
 
    
Posts: 11
Joined: 09-May-2005
# Posted on: 09-May-2005 15:54:20   

I have 2 identical data seating in SQLServer & MySQL, eg: dbname: student on SQLServer & student in MySQL. I have created 2 LLBLGenPro projects, one for each db. I don't know how to call DAL from BLL which pass a param like DBName to fetch correct database.

Example:

BLL: function GetAllStudents(String DBName) { if (DBName == "SQLServer") MyProject.DAL.SQLServer.GetAllStudent(); else (DBName == "MySQL") MyProject.DAL.MySQL.GetAllStudent(); }

The purpose of this is setting DBName in app.config to tell the application which database to use.

Is this something to do with IDataAccessAdapter (my guess after reading a lot in this forum)? However, I can't find any reference or sample source coding using IDataAccessAdapter in Petshop and Northwise example or in your help file.

wvnoort
User
Posts: 96
Joined: 06-Jan-2005
# Posted on: 09-May-2005 16:34:53   

Yes, you need to use the interface IDataAccessAdapter.

You also need a factory class to return the correct data adapter to use. You can find some examples of such factories on the forum. This is roughly what we are doing in our factory method:


public class DataAccessAdapterFactory
{
    public static IDataAccessAdapter GetDataAdapter(string DBName)
    {   
        
        switch(DBName)
        {
            case "SQLServer":
                
                string = conString
                    ... build connection string from configuration

                daToReturn = new SqlServer.DataAccessAdapter(conString, 
                    keepConnectionOpen, CatalogNameUsage.ForceName, configSqlServerCatalog);
                break;

            ... rest of switch ...
        }
        return daToReturn
    }
}


Then in the other layers you can:


IDataAccessAdapter adapter = DataAccessAdapterFactory.GetDataAdapter("SQLServer");
adapter.FetchEntity( ... );

We use this construction to support an application that uses multiple Oracle and SQL Server databases (all having the same database structure).