473,385 Members | 1,907 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,385 software developers and data experts.

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 5360
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Henry Habermacher [MVP Access] | last post by:
Environment: VS2005, ASP.Net 2.0, SQLServer 2000, VB.Net, IIS6 I use a GridView Control which is based on a SQLDataSource. The datasource is based on a Select statement and is filtered by the...
3
by: Bob | last post by:
Over the life of a distributed app, it is possible for the connection string that it was configured with initailly needs to change. You can't scope a connection string setting to user so that it...
4
by: David | last post by:
I cannot get my aspx page (ASP.Net 2.0) to remove the FilterExpression on a SqlDataSource. Can someone tell me what I am doing wrong? Below is the SelectCommand: <asp:SqlDataSource...
3
by: samcogan | last post by:
Im writing an app that needs to let the user choose which SQL server they want to use froma drop down box, then connect to that server. I've been searching for ages to find a way to do this, anyone...
1
by: Corey B | last post by:
I have a page with a DetailsView control and a SQLDataSource control. The SQLDataSource control is connected to an Access database. Everything works fine. Now I want to change the back end...
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...
4
by: =?Utf-8?B?TWFkaXNvbg==?= | last post by:
Hi all, Could I use the sqldatasource with stored-procedure to return multiple recordset? I did not want to have any sqldatasourec in the one page just to return the record back to...
1
by: =?Utf-8?B?QW50b255IExhaQ==?= | last post by:
Dear All, I am not sure I shall post this here. If not, please let me know. I am building a web application using asp.net 2.0 using c# (IIS 5 under XP) with the web developer express edition...
6
by: BillE | last post by:
I have defined connection strings in the settings tab of the properties page of a Windows forms project. Users need to be able to modify the connection string through the application - how do I...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
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,...

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.