Results 1 to 4 of 4

Thread: advice on best practice

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2003
    Posts
    1,489

    advice on best practice

    What is the best method to go about doing this?

    i have a project that is my data access layer for a larger project which in turn is consumed by yet a third project. ( 3 tier design ). I need to be able to tell the data access layer which servers to use during run-time because I am using development servers, production servers and the servers may change names in the future.

    I've implemented a property in each class that is within the data access project that is of the type 'SqlConnection' and any consumer that wishes to use the class must first pass in a reference to it's own sqlConnection object. This forces the upper layers of the whole solution to maintain those objects and forces pretty much every control/class to do this which is a maintenance nightmare.

    This structure was designed on the fly. Is there a 'sexier' way to control the data connections? I'm using c# 2005.

    I'm sure this has been asked a million times but I wasnt sure what keywords to use so I figured I simply spellout my problem.

    Thanks in advance.

  2. #2
    Hyperactive Member drattansingh's Avatar
    Join Date
    Sep 2005
    Posts
    395

    Re: advice on best practice

    I'm not sure that I understand your situation fully. But what I will say is that for me, I use a design taken from Java which is the MVC design - model, view and controller. The model classes / project deals with only the data access layer. The view deals with the interaction with the user e.g. forms, jsps etc. And the controller deals with the interface classes between the view and the model. In java this goes to servlets etc. I use the same approach in C# where I separate these three layers and up to date have not gotten much problems with it. Looking back at your post, I think you did something similar to the MVC concept so I dont know if this answer your question, but its my view. As of design, there are a lot of methodologies out there, just have to choose the best one.

    And nice use of the word sexier.

    Jennifer

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2003
    Posts
    1,489

    Re: advice on best practice

    Thanks for replying Jennifer.

    That's very helpful. What are you doing to dynamically control the database connection strings? Here, I need to be able to point to a development server OR production server at runtime. Someone suggested using the config files and simply put in all known connection strings and during the login process, make a determination of what connection string to use. Then, when a call to a database is made, simply pass in that string each time.

    I question the efficiency of that. It certainly sounds like it would work but I'm hoping I could get some more ideas

    Thanks again!!

    btw, I have everyone at my office now saying 'sexier' when referring to code LOL

  4. #4
    Fanatic Member Slaine's Avatar
    Join Date
    Jul 2002
    Posts
    641

    Re: advice on best practice

    Have a singleton class - or suchlike - that you initialise with the correct connection string - then your data access layer can use this object to reference the connections string.
    Martin J Wallace (Slaine)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width