connection strings in config file

G

Guest

Hello Everyone,

I have a question about storing the connection strings to the database
in a config file or database. My manager wants me to store all the connection
strings in a database, but I think it is easier and faster to store the
connection strings in the config file. I was wondering if anyone has any
opinion on this issue so that I can convince my manager.

Thanks.
 
N

Nicholas Paldino [.NET/C# MVP]

Vinki,

It's definitely a better idea to store your connection strings in the
config file. If you store them in a database, then how are you supposed to
connect to the database in the first place to retrieve them? You need to
have the connection string outside of the database which you are going to
connect to. The logical place to put that is in the config file.
 
G

Guest

Hi Nicholas,

Thanks for your response. I conveyed your meesage to the manager and also
told him that storing them in the database is time taking. He said that
storing the connection string will not be time taking if we get the
connection string from the database and store that string in the cache. I am
not sure what to say about that. I think it is expensive too, but I don't
have anything to support my views.



Nicholas Paldino said:
Vinki,

It's definitely a better idea to store your connection strings in the
config file. If you store them in a database, then how are you supposed to
connect to the database in the first place to retrieve them? You need to
have the connection string outside of the database which you are going to
connect to. The logical place to put that is in the config file.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Vinki said:
Hello Everyone,

I have a question about storing the connection strings to the database
in a config file or database. My manager wants me to store all the
connection
strings in a database, but I think it is easier and faster to store the
connection strings in the config file. I was wondering if anyone has any
opinion on this issue so that I can convince my manager.

Thanks.
 
E

Egghead

It is a very bad idea to put them into the db. However, I can see a very
usefully way to do it this way. For instance, I can change the connection
strings on the fly (fail over). Actually, I will have another class (layer)
connect to the db and get all the connection string in REAL TIME, without
letting user doing anythig. Of course, you can hard code that single path
(web service or db string) in the class or have the string in a config file.
Remember only one string, NOT "STRINGS".
Therefore, it is hard to say without knowing all the details.

--
cheers,
RL
Nicholas Paldino said:
Vinki,

It's definitely a better idea to store your connection strings in the
config file. If you store them in a database, then how are you supposed
to connect to the database in the first place to retrieve them? You need
to have the connection string outside of the database which you are going
to connect to. The logical place to put that is in the config file.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Vinki said:
Hello Everyone,

I have a question about storing the connection strings to the database
in a config file or database. My manager wants me to store all the
connection
strings in a database, but I think it is easier and faster to store the
connection strings in the config file. I was wondering if anyone has any
opinion on this issue so that I can convince my manager.

Thanks.
 
E

Egghead

Actually, if the connection strings WILL NEVER CHANGE ONCE DEPOLY, you
shall do the following test:

(1) read all the connections from the db (there are time needed for connect
to the db and running the query) and put them into the cache

(2) read all the connections from the file and put them into the cache

(3) hard code the string into the app

and find out the time different.

Sorry, where do you learn your programming skill?

--
cheers,
RL
Vinki said:
Hi Nicholas,

Thanks for your response. I conveyed your meesage to the manager and also
told him that storing them in the database is time taking. He said that
storing the connection string will not be time taking if we get the
connection string from the database and store that string in the cache. I
am
not sure what to say about that. I think it is expensive too, but I don't
have anything to support my views.



Nicholas Paldino said:
Vinki,

It's definitely a better idea to store your connection strings in the
config file. If you store them in a database, then how are you supposed
to
connect to the database in the first place to retrieve them? You need to
have the connection string outside of the database which you are going to
connect to. The logical place to put that is in the config file.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Vinki said:
Hello Everyone,

I have a question about storing the connection strings to the
database
in a config file or database. My manager wants me to store all the
connection
strings in a database, but I think it is easier and faster to store the
connection strings in the config file. I was wondering if anyone has
any
opinion on this issue so that I can convince my manager.

Thanks.
 
G

Guest

Hi,

I am not sure why you are saying that it is bad idea to put the connection
strings in the db. Also, I am not sure why are you saying that where I
learned the programming from. I mean to say strings to different database not
string.

Egghead said:
It is a very bad idea to put them into the db. However, I can see a very
usefully way to do it this way. For instance, I can change the connection
strings on the fly (fail over). Actually, I will have another class (layer)
connect to the db and get all the connection string in REAL TIME, without
letting user doing anythig. Of course, you can hard code that single path
(web service or db string) in the class or have the string in a config file.
Remember only one string, NOT "STRINGS".
Therefore, it is hard to say without knowing all the details.

--
cheers,
RL
Nicholas Paldino said:
Vinki,

It's definitely a better idea to store your connection strings in the
config file. If you store them in a database, then how are you supposed
to connect to the database in the first place to retrieve them? You need
to have the connection string outside of the database which you are going
to connect to. The logical place to put that is in the config file.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Vinki said:
Hello Everyone,

I have a question about storing the connection strings to the database
in a config file or database. My manager wants me to store all the
connection
strings in a database, but I think it is easier and faster to store the
connection strings in the config file. I was wondering if anyone has any
opinion on this issue so that I can convince my manager.

Thanks.
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

Vinki said:
Hi Nicholas,

Thanks for your response. I conveyed your meesage to the manager and also
told him that storing them in the database is time taking. He said that
storing the connection string will not be time taking if we get the
connection string from the database and store that string in the cache. I
am
not sure what to say about that. I think it is expensive too, but I don't
have anything to support my views.

This remember me of a friend of mine, one of his first pet project was an
app to log in the DB when the DB went offline :)


Jokes apart, what is his razionale to want the connection strings in the DB?
 
E

Egghead

For instance, if that db is offline, what can you do? Or, costs of
connection time, running the query?
As I said, it really depend on your design and the system natural.

--
cheers,
RL
Vinki said:
Hi,

I am not sure why you are saying that it is bad idea to put the
connection
strings in the db. Also, I am not sure why are you saying that where I
learned the programming from. I mean to say strings to different database
not
string.

Egghead said:
It is a very bad idea to put them into the db. However, I can see a very
usefully way to do it this way. For instance, I can change the connection
strings on the fly (fail over). Actually, I will have another class
(layer)
connect to the db and get all the connection string in REAL TIME, without
letting user doing anythig. Of course, you can hard code that single path
(web service or db string) in the class or have the string in a config
file.
Remember only one string, NOT "STRINGS".
Therefore, it is hard to say without knowing all the details.

--
cheers,
RL
in
message news:[email protected]...
Vinki,

It's definitely a better idea to store your connection strings in
the
config file. If you store them in a database, then how are you
supposed
to connect to the database in the first place to retrieve them? You
need
to have the connection string outside of the database which you are
going
to connect to. The logical place to put that is in the config file.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Hello Everyone,

I have a question about storing the connection strings to the
database
in a config file or database. My manager wants me to store all the
connection
strings in a database, but I think it is easier and faster to store
the
connection strings in the config file. I was wondering if anyone has
any
opinion on this issue so that I can convince my manager.

Thanks.
 
J

John B

Thanks for your response. I conveyed your meesage to the manager and also
told him that storing them in the database is time taking. He said that
storing the connection string will not be time taking if we get the
connection string from the database and store that string in the cache. I am
not sure what to say about that. I think it is expensive too, but I don't
have anything to support my views.

Personally I would normally have a singleton configuration class which
would load my config from the app.config file or database or both.
It wont really matter much where you store the connection strings, so
long as you store your initial connection string external to the
database and application (please don't hard code it).
When your manager says they will be cached, once MSSQL Server reads a
"page" from disk, it will not release that page from memory unless that
memory is needed elsewhere, this is probably the caching he is referring to.

JB
 
S

Samuel R. Neff

How many connection strings do you have? How often do they change?

Normally you only want to store them in a config file because (a) you
need a connection string to get to a db in first place, (b) they can
be encrypted easily in config file in .net 2.0, and (b) caching is
automatic if you use built-in config stuff.

Howeve, an app normally has only a few connection strings at most (1
is most common I'm sure). So if you have a lot and they change a lot,
then it could make sense to store them in the db (updating the config
file can cause serious problems in some apps--like if an asp.net app
updates web.config, it needs permissions to do so and doing so will
trigger a restart of the asp.net app).

So in some, I think the answer is still "it depends", and we need more
info...

HTH,

Sam
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top