views:

43

answers:

2

I have created a web enabled DB for a company as a part of my internship and it's up and ready. However the connection string of the server is already coded by me. But the IT guy said that he wanted me to read the connection string from a file containing various connection strings and choosing whichever it wanted to at that time.

My question is, Is it possible???....If Yes How???

Kindly help me...i had a long session with him trying to understand the concept, still could'nt get it.

Thanking in anticipation Sujit

+1  A: 

This shouldn't be a problem.

Put the connection string in a file, read the file in your program and pass the string in to the database connection object you are using.

This is so common that in .NET the configuration file schema already has a place for connection strings (plus mechanisms to encrypt that section).

Update:

As you indicate that you are using .NET, you should look into the app.config file, in particular the ConfigurationMananger and the ConnectionStrings section/property.

Oded
+4  A: 

How to: Read Connection Strings from the Web.config File

Richard Hein
There is nothing in the question to indicate .NET
Oded
OP has commented that it is. It was a safe bet anyways.
Richard Hein
@Richard - he has now... but it is not certain. I do agree that if he is using SQL-Server, he is probably using an MS language, but it might have been unmanaged C++ :)
Oded
@Oded: the likelihood of a student coding a website in c++ is pretty slim. Also, the likelihood of a student using anything other than a .net language to tie to a MS SQL backend is equally slim.
Chris Lively
@Chris Lively - All I am saying is that there was nothing _definite_ in the question and more info was required.
Oded