469,951 Members | 2,564 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

Dyanically changing connection strings for SqlDataSource

I'm working on a web app that is published to a hosting service. I'm
developing it on my local PC with VS 2005 and SQL Express. The hosting
service DB is SQL Server 2000.

I have two connectionStrings defined in my web.config file, one for the
development db and another for the production db.

When I publish my app to the hosting site, I rename the two connection
strings so that the production string will be the active string in the
production environment.

I'd rather not have to change strings back and forth to make my app work in
either environment.

Is there a best practice for this type of situation?

My app uses a lot of SqlDataSource controls. Is there a way to dynamically
change the name of the connectionString, defined in the SqlDataSource control
at run-time?

Thanks in advance
Matt
Apr 25 '06 #1
4 5132
Hi Matt,

why would you like to publish the web.config file every time?
Personally, I setup a web.config file for development use
(local connection strings, eventually debugging and tracing
turned on) and another one for production use (production
connection strings, debug turned off).

When deploying, only *.as?x and *.dll are uploaded to the
server.

If you should need one web.config file, which in published
together with the app, maybe adding the computer name to
the connection strings would be an option.

<connectionStrings>
<add name="conn.DEV" connectionString="..." />
<add name="conn.LIVE" connectionString="..." />
</connectionStrings>

When accessing the connection strings, just use the
corresponding connection string. The local machine name
can be accessed by System.Environment.MachineName
Would be something like

string connStringName = String.Format( "conn.{0}",
System.Environment.MachineName.ToUpper() );
Regards,
Jens Rieck
http://www.jens-rieck.de

Matt Colegrove schrieb:
I'm working on a web app that is published to a hosting service. I'm
developing it on my local PC with VS 2005 and SQL Express. The hosting
service DB is SQL Server 2000.

I have two connectionStrings defined in my web.config file, one for the
development db and another for the production db.

When I publish my app to the hosting site, I rename the two connection
strings so that the production string will be the active string in the
production environment.

I'd rather not have to change strings back and forth to make my app work in
either environment.

Is there a best practice for this type of situation?

My app uses a lot of SqlDataSource controls. Is there a way to dynamically
change the name of the connectionString, defined in the SqlDataSource control
at run-time?

Thanks in advance
Matt

Apr 25 '06 #2
If I could "publish" without uploading the web.config, that would be ideal.
I was under the impression that the "publish web" function in VS 2005, pushed
a fresh copy of everything to the web. How would I tell it which files not
to publish?

Matt
"Jens Rieck" wrote:
Hi Matt,

why would you like to publish the web.config file every time?
Personally, I setup a web.config file for development use
(local connection strings, eventually debugging and tracing
turned on) and another one for production use (production
connection strings, debug turned off).

When deploying, only *.as?x and *.dll are uploaded to the
server.

If you should need one web.config file, which in published
together with the app, maybe adding the computer name to
the connection strings would be an option.

<connectionStrings>
<add name="conn.DEV" connectionString="..." />
<add name="conn.LIVE" connectionString="..." />
</connectionStrings>

When accessing the connection strings, just use the
corresponding connection string. The local machine name
can be accessed by System.Environment.MachineName
Would be something like

string connStringName = String.Format( "conn.{0}",
System.Environment.MachineName.ToUpper() );
Regards,
Jens Rieck
http://www.jens-rieck.de

Matt Colegrove schrieb:
I'm working on a web app that is published to a hosting service. I'm
developing it on my local PC with VS 2005 and SQL Express. The hosting
service DB is SQL Server 2000.

I have two connectionStrings defined in my web.config file, one for the
development db and another for the production db.

When I publish my app to the hosting site, I rename the two connection
strings so that the production string will be the active string in the
production environment.

I'd rather not have to change strings back and forth to make my app work in
either environment.

Is there a best practice for this type of situation?

My app uses a lot of SqlDataSource controls. Is there a way to dynamically
change the name of the connectionString, defined in the SqlDataSource control
at run-time?

Thanks in advance
Matt

Apr 26 '06 #3
We are using a custom deployment system, but maybe a look at Microsoft's
Web Deployment Projects may help you:
http://msdn.microsoft.com/asp.net/re...structure/wdp/

There's an option called "Enable web.config file section replacement",
allowing you replace a section like <connectionStrings> with the content
of an arbitrary file when deploying your website.

Jens Rieck
http://www.jens-rieck.de

Matt Colegrove schrieb:
If I could "publish" without uploading the web.config, that would be ideal.
I was under the impression that the "publish web" function in VS 2005, pushed
a fresh copy of everything to the web. How would I tell it which files not
to publish?

Matt
"Jens Rieck" wrote:
Hi Matt,

why would you like to publish the web.config file every time?
Personally, I setup a web.config file for development use
(local connection strings, eventually debugging and tracing
turned on) and another one for production use (production
connection strings, debug turned off).

When deploying, only *.as?x and *.dll are uploaded to the
server.

If you should need one web.config file, which in published
together with the app, maybe adding the computer name to
the connection strings would be an option.

<connectionStrings>
<add name="conn.DEV" connectionString="..." />
<add name="conn.LIVE" connectionString="..." />
</connectionStrings>

When accessing the connection strings, just use the
corresponding connection string. The local machine name
can be accessed by System.Environment.MachineName
Would be something like

string connStringName = String.Format( "conn.{0}",
System.Environment.MachineName.ToUpper() );
Regards,
Jens Rieck
http://www.jens-rieck.de

Matt Colegrove schrieb:
I'm working on a web app that is published to a hosting service. I'm
developing it on my local PC with VS 2005 and SQL Express. The hosting
service DB is SQL Server 2000.

I have two connectionStrings defined in my web.config file, one for the
development db and another for the production db.

When I publish my app to the hosting site, I rename the two connection
strings so that the production string will be the active string in the
production environment.

I'd rather not have to change strings back and forth to make my app work in
either environment.

Is there a best practice for this type of situation?

My app uses a lot of SqlDataSource controls. Is there a way to dynamically
change the name of the connectionString, defined in the SqlDataSource control
at run-time?

Thanks in advance
Matt

Apr 27 '06 #4
This looks A LOT like what I want to be able to do!! Thanks

"Jens Rieck" wrote:
We are using a custom deployment system, but maybe a look at Microsoft's
Web Deployment Projects may help you:
http://msdn.microsoft.com/asp.net/re...structure/wdp/

There's an option called "Enable web.config file section replacement",
allowing you replace a section like <connectionStrings> with the content
of an arbitrary file when deploying your website.

Jens Rieck
http://www.jens-rieck.de

Matt Colegrove schrieb:
If I could "publish" without uploading the web.config, that would be ideal.
I was under the impression that the "publish web" function in VS 2005, pushed
a fresh copy of everything to the web. How would I tell it which files not
to publish?

Matt
"Jens Rieck" wrote:
Hi Matt,

why would you like to publish the web.config file every time?
Personally, I setup a web.config file for development use
(local connection strings, eventually debugging and tracing
turned on) and another one for production use (production
connection strings, debug turned off).

When deploying, only *.as?x and *.dll are uploaded to the
server.

If you should need one web.config file, which in published
together with the app, maybe adding the computer name to
the connection strings would be an option.

<connectionStrings>
<add name="conn.DEV" connectionString="..." />
<add name="conn.LIVE" connectionString="..." />
</connectionStrings>

When accessing the connection strings, just use the
corresponding connection string. The local machine name
can be accessed by System.Environment.MachineName
Would be something like

string connStringName = String.Format( "conn.{0}",
System.Environment.MachineName.ToUpper() );
Regards,
Jens Rieck
http://www.jens-rieck.de

Matt Colegrove schrieb:
I'm working on a web app that is published to a hosting service. I'm
developing it on my local PC with VS 2005 and SQL Express. The hosting
service DB is SQL Server 2000.

I have two connectionStrings defined in my web.config file, one for the
development db and another for the production db.

When I publish my app to the hosting site, I rename the two connection
strings so that the production string will be the active string in the
production environment.

I'd rather not have to change strings back and forth to make my app work in
either environment.

Is there a best practice for this type of situation?

My app uses a lot of SqlDataSource controls. Is there a way to dynamically
change the name of the connectionString, defined in the SqlDataSource control
at run-time?

Thanks in advance
Matt

Apr 28 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Henry Habermacher [MVP Access] | last post: by
4 posts views Thread by David | last post: by
3 posts views Thread by samcogan | last post: by
4 posts views Thread by =?Utf-8?B?TWFkaXNvbg==?= | last post: by
1 post views Thread by =?Utf-8?B?QW50b255IExhaQ==?= | last post: by
6 posts views Thread by BillE | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.