473,738 Members | 2,645 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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
programmaticall y 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_Sta rt
method of the Global.asax file:

Dim csNew As ConnectionStrin gSettings

Dim config As Configuration =
System.Web.Conf iguration.WebCo nfigurationMana ger.OpenWebConf iguration(HttpC ontext.Current. Request.Applica tionPath)

csNew = New
ConnectionStrin gSettings(confi g.ConnectionStr ings.Connection Strings("conn") .Name,
"cstring",
config.Connecti onStrings.Conne ctionStrings("S PIncConn").Prov iderName)
If (config.Connect ionStrings.Conn ectionStrings(" conn").Connecti onString <>
"correct cstring") Then
config.Connecti onStrings.Conne ctionStrings.Re move("conn")
config.Connecti onStrings.Conne ctionStrings.Ad d(csNew)
config.Save()
End If

After this runs I can open the web.config and see the correct
connectionStrin g 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 connectionStrin gName 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 3768

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

Similar topics

5
15143
by: ad | last post by:
The Global.asax is code-inside with default. How to change Global.asax to code-behind?
0
227
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 Security=True' as the connection string and 'NET Framework Data Provider for SQL Server' as the provider. Following these settings in my code and I have used the connection string; <add name="Membership" connectionString="Data Source=MYSERVER;Initial
2
5346
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 Security=True' as the connection string and 'NET Framework Data Provider for SQL Server' as the provider. Following these settings in my code and I have used the connection string; <add name="Membership" connectionString="Data Source=MYSERVER;Initial
1
1899
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 setup on the site through the admin interface. So I yanked it out of the application since it did not work. Now everytime I load the site after changing the application I get this error message. If I simply refresh the page, everything works...
3
1275
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; DATABASE=blah***; UID=Blah***; PWD=blah*****
37
8957
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). I then change dynamically the connection string by doing : My.Settings.Item("ConnectionString") = "some connection sring" The problem is that if another user loggs in and chooses another client, then obviously it changes the connection string...
7
9279
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 Application_Start set the Application to the relevant ConnectionString from the web.config based upon the domain (so we can handle dev/test/live, etc). The problem we have is that we can't see how to dynamically set the
1
1445
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 provider which simply send the username and password to the web service and I get back a user ID if authentication passes. The problem is that I don't know how to get the UserID back to the login
4
1570
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: Public Function StringConnection() As String Return "Server=myservername;Database=mydatabasename;User ID=myid;Password=mypassword;" End Function
0
8787
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9473
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9259
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9208
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6750
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6053
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4569
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3279
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2744
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.