468,268 Members | 2,002 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,268 developers. It's quick & easy.

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 3493

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by John | last post: by
1 post views Thread by Chris Love | last post: by
3 posts views Thread by BobLaughland | last post: by
37 posts views Thread by sam44 | last post: by
4 posts views Thread by glbdev | last post: by
reply views Thread by kermitthefrogpy | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.