Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. problem when creating database independant access layer

problem when creating database independant access layer

Scheduled Pinned Locked Moved Database
databasehelpcsharpsql-serversysadmin
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    Hassan Amaar
    wrote on last edited by
    #1

    I tried to create database independant using new feature of visual .net(factories)the problem happen when passing parameters for orcale and sql server the shape of this passed parms differs that will genrate error when passing parameter or i will have to write code for diffrent diffrent database cases & that will be on the contrary of the reason of factories and exisance. thanks alot Hassan amaar.

    Hassan Amaar

    P H 2 Replies Last reply
    0
    • H Hassan Amaar

      I tried to create database independant using new feature of visual .net(factories)the problem happen when passing parameters for orcale and sql server the shape of this passed parms differs that will genrate error when passing parameter or i will have to write code for diffrent diffrent database cases & that will be on the contrary of the reason of factories and exisance. thanks alot Hassan amaar.

      Hassan Amaar

      P Offline
      P Offline
      Paddy Boyd
      wrote on last edited by
      #2

      I think you're maybe missing the point of the factory pattern - in what way do the passed parameters change?

      H 1 Reply Last reply
      0
      • H Hassan Amaar

        I tried to create database independant using new feature of visual .net(factories)the problem happen when passing parameters for orcale and sql server the shape of this passed parms differs that will genrate error when passing parameter or i will have to write code for diffrent diffrent database cases & that will be on the contrary of the reason of factories and exisance. thanks alot Hassan amaar.

        Hassan Amaar

        H Offline
        H Offline
        Hayder Marzouk
        wrote on last edited by
        #3

        Hi, In fact they are different : SQLServer provider : @ + name Oracle : p + name OleDB : ? (without a name) ODBC (i think) : ? (without a name) Me too i don't know why MS decided to change parameter names with providers. It's as is it and we must deal with that. There are many other differences : - Data Types - Quotes : []in sql and access , "" in Oracle,.... - And Queries are different so use only standard SQL (SQL-92 or SQL-99) to be sure that u don't need to rewrite your application when changing provider. I think u must create a class for each provider and declare diffrences as variables that u change in each class. I am sure that's the better way. HTH. Hayder Marzouk

        H 1 Reply Last reply
        0
        • P Paddy Boyd

          I think you're maybe missing the point of the factory pattern - in what way do the passed parameters change?

          H Offline
          H Offline
          Hassan Amaar
          wrote on last edited by
          #4

          Thanks alot for yuor replay, it differs in the the way the prameter are passed for instance when passing aprameter to orcale prvider it will be like this :p + name for Sqlprovider it will be like this :@ + name so in this case according to what I understood I will have to create aclass for each data provider. I will do appreciate if you told if there is better solution,and please give me an example. Hassan amaar

          Hassan Amaar

          P 1 Reply Last reply
          0
          • H Hayder Marzouk

            Hi, In fact they are different : SQLServer provider : @ + name Oracle : p + name OleDB : ? (without a name) ODBC (i think) : ? (without a name) Me too i don't know why MS decided to change parameter names with providers. It's as is it and we must deal with that. There are many other differences : - Data Types - Quotes : []in sql and access , "" in Oracle,.... - And Queries are different so use only standard SQL (SQL-92 or SQL-99) to be sure that u don't need to rewrite your application when changing provider. I think u must create a class for each provider and declare diffrences as variables that u change in each class. I am sure that's the better way. HTH. Hayder Marzouk

            H Offline
            H Offline
            Hassan Amaar
            wrote on last edited by
            #5

            Thanks you for your replay I think what you said is the only way to deal with this case Hassan Amaar

            Hassan Amaar

            1 Reply Last reply
            0
            • H Hassan Amaar

              Thanks alot for yuor replay, it differs in the the way the prameter are passed for instance when passing aprameter to orcale prvider it will be like this :p + name for Sqlprovider it will be like this :@ + name so in this case according to what I understood I will have to create aclass for each data provider. I will do appreciate if you told if there is better solution,and please give me an example. Hassan amaar

              Hassan Amaar

              P Offline
              P Offline
              Paddy Boyd
              wrote on last edited by
              #6

              Well yes, this is really the idea behind the factory pattern, something like:

              DalFactory fact = new DalFactory();

              fact.GetDal();

              then in the factory class:

              GetDal()
              {
              IDal aDataLayerClass;

              switch (source)
              {
              case "SqlServer":

                   aDataLayerClass = new SqlServerDal();
                   break;
              
                case "Oracle":
              
                   aDataLayerClass = new OracleDal();
                   break;
              
                etc...
              

              }

              return aDataLayerClass;
              }

              This means that whatever is calling your data layer, it doesn't matter to them what the datasource is in the background, as they are just dealing with a class like IDal, and you can write provider specific code for each datasource.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups