473,326 Members | 2,081 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

How can I change the connection string for a Membership Provider in the Global.asax file?

Hi -

I have a site that runs on a development and production server. I'd like to
programmatically change the connection string the provider uses in the
web.config file and have the provider use the updated string. I am able to
successfully change the string using this code in the Application_Start
method of the Global.asax file:

Dim csNew As ConnectionStringSettings

Dim config As Configuration =
System.Web.Configuration.WebConfigurationManager.O penWebConfiguration(HttpContext.Current.Request.Ap plicationPath)

csNew = New
ConnectionStringSettings(config.ConnectionStrings. ConnectionStrings("conn").Name,
"cstring",
config.ConnectionStrings.ConnectionStrings("SPIncC onn").ProviderName)
If (config.ConnectionStrings.ConnectionStrings("conn" ).ConnectionString <>
"correct cstring") Then
config.ConnectionStrings.ConnectionStrings.Remove( "conn")
config.ConnectionStrings.ConnectionStrings.Add(csN ew)
config.Save()
End If

After this runs I can open the web.config and see the correct
connectionString entry is in it. So that is working. However when I try to
log in the Membership system in ASP.Net is still hooked up to the old
database somehow. From what I've read I figured maybe the config.Save()
method would cause an app restart which would in turn cause the Membership
stuff to sync with the new database. The connectionStringName propery in my
provider doesn't need to change because when I alter it I'm using the same
name.

I think this is being cached somewhere. The weirdest part is if I go into
IIS, stop the app, then restart it, it is still hooked up to the wrong DB
even though I can physically open the web.config and see that it is now
holding the correct string for that server. However if I physically reboot
the whole server it then notices the new string and works just fine.

Does anyone know where this would be cached or stored outside of the
application itself? When I run locally through VS.Net 2005 this works like
a charm. It isn't a permission issue with modifying the web.config because
I can see that the file is being modified successfully on the server.
Thanks for any insight!

Feb 15 '07 #1
0 3738

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: ad | last post by:
The Global.asax is code-inside with default. How to change Global.asax to code-behind?
0
by: John | last post by:
Hi I am manually able to create a connection to my db in the vs2005 ide using Tools->Connect to Database. In the connection I see 'Data Source=MYSERVER;Initial Catalog=aspnetdb;Integrated...
2
by: John | last post by:
Hi I am manually able to create a connection to my db in the vs2005 ide using Tools->Connect to Database. In the connection I see 'Data Source=MYSERVER;Initial Catalog=aspnetdb;Integrated...
1
by: Chris Love | last post by:
I have already asked this, but no one seems to know the answer. Here is the timeline. I wanted to use the membership/roles functionality in a site. I got all sorts of errors trying to get this...
3
by: BobLaughland | last post by:
Hi There, I am writing an ASP .NET 2.0 web site. I have a connection string in my web.config file similar to this for connecting to my database, SERVER=125.165.165.116,1092;...
37
by: sam44 | last post by:
Hi, At startup the user log on and chooses the name of a client from a dropdownlist, which then changes dynamically the connection string (the name of the client indicates which database to use)....
7
by: Larry Neylon | last post by:
Hi there, We are in the process of implementing Membership and Role Management and have a problem with the connection strings in our web.config. We currently have a system that on...
1
by: Erik | last post by:
Hi Everyone, Hopefully this is an easy one. I've googled around for the answer but cant find it. I have simple login page that authenticates via a web service. I am using a custom membership...
4
by: glbdev | last post by:
Hi. I am having an problem connecting to a remote SQL Server. Other applications (using access) are connection to it but I cannot get it to work through ASP.Net. Here is my connection string:...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.