Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8829105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T07:45:31+00:00 2026-06-14T07:45:31+00:00

I need to build a Data Access Library to be used from many small

  • 0

I need to build a Data Access Library to be used from many small applications afterwards.

It will heavily use the DataReader objects. The tables may exist with same structure either in SQL Servers or in DB2/400. This means that a method for example

GetItemsByWarehouse()

Must be able to run either against SQL Server DB or DB2. Where it will run depends on the server availability and user selection.

What i plan to do (and need advice on it) is :

  1. Implement the DAL based on Singleton design Pattern to ensure that i will have only one instance of my Library.
  2. Have a property that will set the connection string.
  3. Have a property that will set if the target server is AS400 or SQL.

I dont know if this course of action is correct. Should i implement point #3 or i could get the type from the connection string?

Also How i should implement such a method as above? check the property and decide inside the method if i will use Sqlconnection or OleDbConnection e.t.c?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T07:45:32+00:00Added an answer on June 14, 2026 at 7:45 am

    I paste this code from my micro Orm . There are multiple overloads for the constructor to specify what Db you want used.

     public class DbAccess : IDisposable
    {
        public DbAccess()
        {
            var cnx=ConfigurationManager.ConnectionStrings[0];
            if (cnx==null) throw new InvalidOperationException("I need a connection!!!");
    
            Init(cnx.ConnectionString,ProviderFactory.GetProviderByName(cnx.ProviderName));
        }
    
        public DbAccess(string connectionStringName)
        {
            var cnx = ConfigurationManager.ConnectionStrings[connectionStringName];
            if (cnx == null) throw new InvalidOperationException("I need a connection!!!");
    
            Init(cnx.ConnectionString, ProviderFactory.GetProviderByName(cnx.ProviderName));
        }
    
        public DbAccess(string cnxString,string provider)
        {
            Init(cnxString,ProviderFactory.GetProviderByName(provider));
        }
    
        public DbAccess(string cnxString,DBType provider)
        {
          Init(cnxString,ProviderFactory.GetProvider(provider));
        }
    
        public DbAccess(string cnxString,IHaveDbProvider provider)
        {
            Init(cnxString, provider);
        } //other stuff
       }
    

    Note that the DAO (DbAccess) doesn’t care about the concrete provider.
    Here’s how the ProviderFactory looks. Here you can add a method to detect the db and to return a provider.

       internal static class ProviderFactory
    {
        public static IHaveDbProvider GetProviderByName(string providerName)
        {
            switch (providerName)
            {
                case SqlServerProvider.ProviderName:return new SqlServerProvider();
                case MySqlProvider.ProviderName:return new MySqlProvider();
                case PostgresProvider.ProviderName:return new PostgresProvider();
                case OracleProvider.ProviderName:return new OracleProvider();
                case SqlServerCEProvider.ProviderName:return new SqlServerCEProvider();
                case SqliteProvider.ProviderName:return new SqliteProvider();
            }
            throw new Exception("Unkown provider");
        }
    
        public static IHaveDbProvider GetProvider(DBType type)
        {
            switch (type)
            {
                case DBType.SqlServer: return new SqlServerProvider();
                case DBType.SqlServerCE: return new SqlServerCEProvider();
                case DBType.MySql: return new MySqlProvider();
                case DBType.PostgreSQL:return new PostgresProvider();
                case DBType.Oracle:return new OracleProvider();
                case DBType.SQLite:return new SqliteProvider();
            }
            throw new Exception("Unkown provider");
        }
    }
    

    For more code snippets and inspiration you can check the Github repo

    I would advice against the Singleton pattern, it’s much better to let a DI container to manage the instance life. Also, the app should use the interface of the DAO not the concrete instance (this will help you in the future).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to access the data from my xcode project's full_settings.xcconfig file. I was
I need to build a reporting system that would pull the data from a
I have a need to build the data string dynamically. This is not working,
I need to build an application that accepts user input data (such as name,
I need to build a feature like most of the banks use. Where.. if
I need to build some client side code which follows this use case: An
I need to build a multidimensional array from records retrieved from my database. Here
I use a dbml for my Data Access Layer to provide the data that
There's this web app, which relies on a sort of data access library (simple
I need to build very concurrent web service which will expose REST based API

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.