469,623 Members | 1,192 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

AspNetSqlMembershipProvider connection string changing at runtime

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["connection_string"] 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
connectionStringName properties in the web.config for
AspNetSqlMembershipProvider, AspNetSqlRoleProvider, etc.

My questions are:

a) Is there a better way to handle the multiple sites / connections strings
issues than working out the correct one on app startup ?

b) If what we are doing isn't insane, how can you dynamically set the
connectionStringName for the Membership and Roles stuff ?

Any help or advice would be much appreciated.

Regards,
Larry.
Apr 11 '07 #1
7 9039
Interesting question! There could be several approaches to this, the simplest
of which would be to simply have a web.config file containing the correct
element values for the particular deployment scenario, of course.

However, if you look here:

http://msdn2.microsoft.com/en-us/library/ms178411.aspx

you may get some ideas on how this can be dynamically altered and saved at
application startup (say, in Application_Start handler in Global.asax)
Peter

--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"Larry Neylon" wrote:
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["connection_string"] 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
connectionStringName properties in the web.config for
AspNetSqlMembershipProvider, AspNetSqlRoleProvider, etc.

My questions are:

a) Is there a better way to handle the multiple sites / connections strings
issues than working out the correct one on app startup ?

b) If what we are doing isn't insane, how can you dynamically set the
connectionStringName for the Membership and Roles stuff ?

Any help or advice would be much appreciated.

Regards,
Larry.
Apr 12 '07 #2
google for "Web Deployment Projects" - a MS add in for VS.

They allow you based on build configuration to change the connection string
section in web.config.
-----
Dominick Baier (http://www.leastprivilege.com)

Developing More Secure Microsoft ASP.NET 2.0 Applications (http://www.microsoft.com/mspress/books/9989.asp)
Interesting question! There could be several approaches to this, the
simplest of which would be to simply have a web.config file containing
the correct element values for the particular deployment scenario, of
course.

However, if you look here:

http://msdn2.microsoft.com/en-us/library/ms178411.aspx

you may get some ideas on how this can be dynamically altered and
saved at application startup (say, in Application_Start handler in
Global.asax) Peter

"Larry Neylon" wrote:
>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["connection_string"] 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
connectionStringName properties in the web.config for
AspNetSqlMembershipProvider, AspNetSqlRoleProvider, etc.

My questions are:

a) Is there a better way to handle the multiple sites / connections
strings issues than working out the correct one on app startup ?

b) If what we are doing isn't insane, how can you dynamically set
the connectionStringName for the Membership and Roles stuff ?

Any help or advice would be much appreciated.

Regards,
Larry.

Apr 12 '07 #3
Thanks for that Peter,

One question, which i can't answer myself as I'm not in the office.

Is the web.config updatable from the Application_Start ? i.e. can I have a
configuration string called "default", which I update in the
Application_Start to the value I need based upon environment, and then have
all the other references like AspNetSqlMembershipProvider point to "default"
?

Many thanks,
Larry.
"Peter Bromberg [C# MVP]" <pb*******@yahoo.yabbadabbadoo.comwrote in
message news:6B**********************************@microsof t.com...
Interesting question! There could be several approaches to this, the
simplest
of which would be to simply have a web.config file containing the correct
element values for the particular deployment scenario, of course.

However, if you look here:

http://msdn2.microsoft.com/en-us/library/ms178411.aspx

you may get some ideas on how this can be dynamically altered and saved at
application startup (say, in Application_Start handler in Global.asax)
Peter

--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"Larry Neylon" wrote:
>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["connection_string"] 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
connectionStringName properties in the web.config for
AspNetSqlMembershipProvider, AspNetSqlRoleProvider, etc.

My questions are:

a) Is there a better way to handle the multiple sites / connections
strings
issues than working out the correct one on app startup ?

b) If what we are doing isn't insane, how can you dynamically set the
connectionStringName for the Membership and Roles stuff ?

Any help or advice would be much appreciated.

Regards,
Larry.

Apr 12 '07 #4
SAL
While this website acutally is using the wrong name for configuration and imports the wrong library, if you substitute:
Imports System.Configuration
with
Imports System.Web.Configuration

And substitute
ConfigurationMananger
with
WebConfigurationManager

it shows you how to do just what you are talking about:
http://www.ondotnet.com/pub/a/dotnet...onnstring.html

HTH

S

"Larry Neylon" <ld********@ntlworld.comwrote in message news:0e***************@newsfe4-gui.ntli.net...
Thanks for that Peter,

One question, which i can't answer myself as I'm not in the office.

Is the web.config updatable from the Application_Start ? i.e. can I have a
configuration string called "default", which I update in the
Application_Start to the value I need based upon environment, and then have
all the other references like AspNetSqlMembershipProvider point to "default"
?

Many thanks,
Larry.
"Peter Bromberg [C# MVP]" <pb*******@yahoo.yabbadabbadoo.comwrote in
message news:6B**********************************@microsof t.com...
>Interesting question! There could be several approaches to this, the
simplest
of which would be to simply have a web.config file containing the correct
element values for the particular deployment scenario, of course.

However, if you look here:

http://msdn2.microsoft.com/en-us/library/ms178411.aspx

you may get some ideas on how this can be dynamically altered and saved at
application startup (say, in Application_Start handler in Global.asax)
Peter

--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"Larry Neylon" wrote:
>>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["connection_string"] 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
connectionStringName properties in the web.config for
AspNetSqlMembershipProvider, AspNetSqlRoleProvider, etc.

My questions are:

a) Is there a better way to handle the multiple sites / connections
strings
issues than working out the correct one on app startup ?

b) If what we are doing isn't insane, how can you dynamically set the
connectionStringName for the Membership and Roles stuff ?

Any help or advice would be much appreciated.

Regards,
Larry.
Apr 12 '07 #5
Larry,
Under ASP.NET 2.0, the new ConfigurationManager class has methods that allow
you to read, modify and save most any kind of configuration data. All you
would need to do in Application_Start is to get the metadata you need
(hostname, whatever) to determine "what environment" this is, modify the
web.config appropriately, including saving a special key so it doesn't keep
doing it over and over again, and you can get the results you want.

I'd still be more inclined to use an MSBuild or other deployment arrangement
however, rather than attempting to change this kind of stuff on the fly at
runtime.
Peter

--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"Larry Neylon" wrote:
Thanks for that Peter,

One question, which i can't answer myself as I'm not in the office.

Is the web.config updatable from the Application_Start ? i.e. can I have a
configuration string called "default", which I update in the
Application_Start to the value I need based upon environment, and then have
all the other references like AspNetSqlMembershipProvider point to "default"
?

Many thanks,
Larry.
"Peter Bromberg [C# MVP]" <pb*******@yahoo.yabbadabbadoo.comwrote in
message news:6B**********************************@microsof t.com...
Interesting question! There could be several approaches to this, the
simplest
of which would be to simply have a web.config file containing the correct
element values for the particular deployment scenario, of course.

However, if you look here:

http://msdn2.microsoft.com/en-us/library/ms178411.aspx

you may get some ideas on how this can be dynamically altered and saved at
application startup (say, in Application_Start handler in Global.asax)
Peter

--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"Larry Neylon" wrote:
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["connection_string"] 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
connectionStringName properties in the web.config for
AspNetSqlMembershipProvider, AspNetSqlRoleProvider, etc.

My questions are:

a) Is there a better way to handle the multiple sites / connections
strings
issues than working out the correct one on app startup ?

b) If what we are doing isn't insane, how can you dynamically set the
connectionStringName for the Membership and Roles stuff ?

Any help or advice would be much appreciated.

Regards,
Larry.


Apr 13 '07 #6
In addition - changing the web.config at runtime causes an app domain recycle
and you may loose session or cache data...
-----
Dominick Baier (http://www.leastprivilege.com)

Developing More Secure Microsoft ASP.NET 2.0 Applications (http://www.microsoft.com/mspress/books/9989.asp)
Larry,
Under ASP.NET 2.0, the new ConfigurationManager class has methods that
allow
you to read, modify and save most any kind of configuration data. All
you
would need to do in Application_Start is to get the metadata you need
(hostname, whatever) to determine "what environment" this is, modify
the
web.config appropriately, including saving a special key so it doesn't
keep
doing it over and over again, and you can get the results you want.
I'd still be more inclined to use an MSBuild or other deployment
arrangement
however, rather than attempting to change this kind of stuff on the
fly at
runtime.
Peter
"Larry Neylon" wrote:
>Thanks for that Peter,

One question, which i can't answer myself as I'm not in the office.

Is the web.config updatable from the Application_Start ? i.e. can I
have a configuration string called "default", which I update in the
Application_Start to the value I need based upon environment, and
then have all the other references like AspNetSqlMembershipProvider
point to "default" ?

Many thanks,
Larry.
"Peter Bromberg [C# MVP]" <pb*******@yahoo.yabbadabbadoo.comwrote
in message news:6B**********************************@microsof t.com...
>>Interesting question! There could be several approaches to this, the
simplest
of which would be to simply have a web.config file containing the
correct
element values for the particular deployment scenario, of course.
However, if you look here:

http://msdn2.microsoft.com/en-us/library/ms178411.aspx

you may get some ideas on how this can be dynamically altered and
saved at application startup (say, in Application_Start handler in
Global.asax) Peter

--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net
"Larry Neylon" wrote:

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["connection_string"] 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
connectionStringName properties in the web.config for
AspNetSqlMembershipProvider, AspNetSqlRoleProvider, etc.

My questions are:

a) Is there a better way to handle the multiple sites /
connections
strings
issues than working out the correct one on app startup ?
b) If what we are doing isn't insane, how can you dynamically set
the connectionStringName for the Membership and Roles stuff ?

Any help or advice would be much appreciated.

Regards,
Larry.

Apr 13 '07 #7
Exactly. But if he coded it correctly, it would only happen the one time that
he modifies his web.config, hence the suggestion to have some sort of special
"flag" to prevent it from happening over and over.
Not to be pedantic, but you don't "loose" Session or Cache data. Your pants
may be "loose", which could then cause you to "lose" them. :-)
--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"Dominick Baier" wrote:
In addition - changing the web.config at runtime causes an app domain recycle
and you may loose session or cache data...
-----
Dominick Baier (http://www.leastprivilege.com)

Developing More Secure Microsoft ASP.NET 2.0 Applications (http://www.microsoft.com/mspress/books/9989.asp)
Larry,
Under ASP.NET 2.0, the new ConfigurationManager class has methods that
allow
you to read, modify and save most any kind of configuration data. All
you
would need to do in Application_Start is to get the metadata you need
(hostname, whatever) to determine "what environment" this is, modify
the
web.config appropriately, including saving a special key so it doesn't
keep
doing it over and over again, and you can get the results you want.
I'd still be more inclined to use an MSBuild or other deployment
arrangement
however, rather than attempting to change this kind of stuff on the
fly at
runtime.
Peter
"Larry Neylon" wrote:
Thanks for that Peter,

One question, which i can't answer myself as I'm not in the office.

Is the web.config updatable from the Application_Start ? i.e. can I
have a configuration string called "default", which I update in the
Application_Start to the value I need based upon environment, and
then have all the other references like AspNetSqlMembershipProvider
point to "default" ?

Many thanks,
Larry.
"Peter Bromberg [C# MVP]" <pb*******@yahoo.yabbadabbadoo.comwrote
in message news:6B**********************************@microsof t.com...

Interesting question! There could be several approaches to this, the
simplest
of which would be to simply have a web.config file containing the
correct
element values for the particular deployment scenario, of course.
However, if you look here:

http://msdn2.microsoft.com/en-us/library/ms178411.aspx

you may get some ideas on how this can be dynamically altered and
saved at application startup (say, in Application_Start handler in
Global.asax) Peter

--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net
"Larry Neylon" wrote:

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["connection_string"] 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
connectionStringName properties in the web.config for
AspNetSqlMembershipProvider, AspNetSqlRoleProvider, etc.

My questions are:

a) Is there a better way to handle the multiple sites /
connections
strings
issues than working out the correct one on app startup ?
b) If what we are doing isn't insane, how can you dynamically set
the connectionStringName for the Membership and Roles stuff ?

Any help or advice would be much appreciated.

Regards,
Larry.


Apr 13 '07 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

10 posts views Thread by Brian Conway | last post: by
6 posts views Thread by Jon Davis | last post: by
12 posts views Thread by Charlie | last post: by
6 posts views Thread by Bala Nagarajan | last post: by
3 posts views Thread by samcogan | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.