[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2014-08-04
4
Medium Priority
?
22 Views
Last Modified: 2016-06-10
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?
0
Comment
Question by:Saroj13
3 Comments
 
LVL 16

Accepted Solution

by:
Easwaran Paramasivam earned 1000 total points
ID: 40240422
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
 
LVL 52

Assisted Solution

by:Carl Tawn
Carl Tawn earned 1000 total points
ID: 40240856
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
 

Author Comment

by:Saroj13
ID: 40241547
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

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…

825 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question