C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




How to change Connection string dynamically using Application_BeginRequest


Posted Date: 09 Jun 2008    Resource Type: Code Snippets    Category: ASP.NET WebForms
Author: BalasubramaniyamMember Level: Gold    
Rating: Points: 10



You developed webapplication, you hosted in two different server.One server name is
"Production" and another server name is "Testing". The below code connection string will change dynamically based on server host information.


<appsettings>
<add key="production" value="http://www.production.com">
<add key="ProductionconnectionString" value="server=localhost;...." >
<add key="testconnectionString" value="server=localhost;...." >
</appsettings>
Public Application_BeginRequest()
{
bool production=false;
if(Request.URL.Host==ConfiqurationManager.Appsettings("production"))
{
Production=true;
}
}

if(Production==true)
{
context.items.add("connectionStrings",ConfiqurationManager.Appsettings("production"))
}
else
{
context.items.add("connectionStrings",ConfiqurationManager.Appsettings("test"))
}
}




Responses

Author: vijetha    10 Jun 2008Member Level: Gold   Points : 0
THIS IS VERY GOOD AND USEFUL


Author: MaheshKumar    23 Jul 2008Member Level: Gold   Points : 1
hi bala,

This is post is very useful.

Keep it up.

Regards,
Mahesh (PIC)


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Eliminate Duplicate Values in a Sorted Array
Previous Resource: Convert Excel file into Dataset
Return to Discussion Resource Index
Post New Resource
Category: ASP.NET WebForms


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design


Contact Us    Privacy Policy    Terms Of Use