How to get the connection string depending upon the url parameter passed in c#, asp.net?

Hi,

I am having ItemList Application. This application is used by 20 applications and each of them have separate database. From each 20 applications, I want to open the ItemList application and value is inserted in the corresponding database.

ItemList application is not having its own database. ItemList is using the database depending upon the application called.

 <A href="ItemList/Login.aspx?AppID=CallApp" target="_self">ItemList</A>

How this can be achieved?
Saroj13Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Easwaran ParamasivamCommented:
All the 20 applications connection strings could be either saved in config file or in database. Say for example in config file use different keys in <appsettings> section.

<appsetting key="App1"  value="ConnectionString1">
....

Likewise if you want in database

ID Value
App1 ConnnectionString1
...........

Then read the value from the config value or from DB and use accordingly.

You have some other options as well. Store the connection strings in XML file and read the XML file and store it in dictionary object or Cache. So that you could read from there at ease.  This is applicable if the connection strings are not subject to frequent change.

HTH.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Carl TawnSystems and Integration DeveloperCommented:
Is the whole connection string different, or is it just the database name?

If it's just the database name, you could store a parameterised connection in the config file and simply substitute the database name at runtime:
// example config file
<connectionStrings>
    <add name="AppConnection" connectionString="Server=SomeServer;Initial Catalog={0};User ID=blah;PWD=blah;" providerName="System.Data.SqlClient" />
</connectionString>

Open in new window

Then in code:
string appName = "CallApp";
string connectionString = string.Format(ConfigurationManager.ConnectionStrings["AppConnection"], appName);

Open in new window

Of course you wouldn't really want to be passing database names around in visible code, so a table of pseudonyms for application/database name pairs would be appropriate.
0
Saroj13Author Commented:
ItemList application is ued by 20 applications. Each 20 application is having corresponding Database.

App1
<A href="ItemList/Login.aspx?AppID=App1" target="_self">ItemList</A>
App1 is having Database App1. App1 Database is having 3 corresponding ItemList tables.

App2
<A href="ItemList/Login.aspx?AppID=App2" target="_self">ItemList</A>
App2 is having Database App2. App2 Database is having 3 corresponding ItemList  tables.

ItemList application, depending upon the Parameter passed in the url, use the corresponding database. If Itemlist app is open from App1 application, then Itemlist app uses App1 Database.

If Itemlist app is open from App2 application, then Itemlist app uses App2 Database.

ItemList is the generic application.

Thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.