SQL Connection - Connection strings

  • Thread starter Thread starter michaeltours
  • Start date Start date
M

michaeltours

I've got an n-Tier web app. I've recently had to re-write our data tier as it was not really doing what we needed. However, as this is my first crack at writing a data-tier I've got one simple question.

What is the best way to store / manage Connection strings. The previous version of this component let developers pass the connectionstring to the datalayer from Business components (which I thought was wrong because 98% of the time we only connect to one physical database). I've written the new component so that it retrieves the connection string from machine.config (where it is encrypted), but now that I have 2 connection strings is this still the best way

How should I be storing connection strings and should my datatier component know which one to use or should it be passed in by different Business objects
 
Here are the preferred ways in order of preference -

a) Windows rights, CAS, so you have no connection string.
b) Encrypted Connection string that involves windows authentication stored
in a config file
c) Encrypted Conn str in a config file that uses Sql Serv. Auth.

- Sahil Malik
http://dotnetjunkies.com/weblog/sahilmalik

michaeltours said:
I've got an n-Tier web app. I've recently had to re-write our data tier as
it was not really doing what we needed. However, as this is my first crack
at writing a data-tier I've got one simple question.
What is the best way to store / manage Connection strings. The previous
version of this component let developers pass the connectionstring to the
datalayer from Business components (which I thought was wrong because 98% of
the time we only connect to one physical database). I've written the new
component so that it retrieves the connection string from machine.config
(where it is encrypted), but now that I have 2 connection strings is this
still the best way?
How should I be storing connection strings and should my datatier
component know which one to use or should it be passed in by different
Business objects ?
 
Thanks for the reply, but it's not really what I asked. I have chosen to store my connection strings in the machine.config already. What I want to know is if I have 2 different SQL servers to connect to, should I be passing the connection string to the Data tier from a business component, or should my data tier be clever enough to work out which connection string to use
 
The whole purpose of a Data layer is to shield the business layer from
any knowledge of the backend db implementation details. If the
Business layer passes the connection string then you are missing the
point of having a data layer in the first place. If which actual db to
use really is actually business rule and not an implementation detail
you could have two separate data layers and have the business component
select the appropriate one or implement a single data layer and have a
hint passed in that tells the data layer which DB to use. I would have
to better understand the business model to say which to use but I think
it is likely that it is just an implementation detail so the data layer
should take care of it.

Cecil Howell MCSD, MCAD.Net, MCT
 
Cheers. I realise that Passing Connection strings fro mthe business layer is incorrect which is why I am trying to sort it out. I think passing hint to the Data layer is a good idea, but was still wondering if this was the best way forward. Bearing in mind that these types of calls are about 1% of calls made so I think the Different Data Layers for each connection is overkill

Thanks again !
 
Michael,
My last sentence was very poorly written what I was trying to say
is:
I would have to better understand the business model to say which to
use (DL totally responsible or BL passing hint) but I think it is
likely that it is just an implementation detail so the data layer
should take care of deciding which connection to use without any hint.

On the other hand it may be that the choice of connection falls under
the category of bussiness rule and then you should have BL pass a hint,
it is probably not black and white.
If you want to post more info I could give you my opinion of which
approach I would use, but I suspect you already have an idea.
Hope this helps

Cecil Howell MCSD, MCAD.Net, MCT
 
Back
Top