Im trying to create a Web Deployment Project, the built in setup and deployment is very good in Visual Studio, i need to able to add an additional step in the setup to change the connection string in the Web config file. Ive seen a
lot of articles on how to do this and in particular this
http://weblogs.asp.net/scottgu/archive/2007/06/15/tip-trick-creating-packaged-asp-net-setup-programs-with-vs-2005.aspx#7162670 I am however stuck on the final part of this tutorial, im using the code Scott provided but have two errors, heres part of my
code where the errors are
using System;
using System.Configuration;
using System.Configuration.Install;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.DirectoryServices;
void ConfigureDatabase(string targetSite, string targetVDir, string connectionString)
{
// Retrieve "Friendly Site Name" from IIS for TargetSite
DirectoryEntry entry = new DirectoryEntry("IIS://LocalHost/" + targetSite);
string friendlySiteName = entry.Properties["ServerComment"].Value.ToString();
// Open Application's Web.Config
Configuration config = WebConfigurationManager.OpenWebConfiguration("/" + targetVDir, friendlySiteName);
// Add new connection string setting for web.config
ConnectionStringSettings appDatabase = new ConnectionStringSettings();
appDatabase.Name = DATABASE_CONNECTION_KEY;
appDatabase.ConnectionString = connectionString;
config.ConnectionStrings.ConnectionStrings.Clear();
config.ConnectionStrings.ConnectionStrings.Add(appDatabase);
// Persist web.config settings
config.Save();
}
my errors are that "WebConfigurationManager" and "DATABASE_CONNECTION_KEY" don't exist in current context do i need to add additional assembly references
and if so which ones? I'm not used to creating web deployment projects but i think this is one of my last steps, would appreciate any help.
nt86
Member
19 Points
42 Posts
Modifying connection String in Web config using Install Wizard
Feb 11, 2010 02:05 PM|LINK
Hey,
Im trying to create a Web Deployment Project, the built in setup and deployment is very good in Visual Studio, i need to able to add an additional step in the setup to change the connection string in the Web config file. Ive seen a lot of articles on how to do this and in particular this http://weblogs.asp.net/scottgu/archive/2007/06/15/tip-trick-creating-packaged-asp-net-setup-programs-with-vs-2005.aspx#7162670 I am however stuck on the final part of this tutorial, im using the code Scott provided but have two errors, heres part of my code where the errors are
void ConfigureDatabase(string targetSite, string targetVDir, string connectionString) { // Retrieve "Friendly Site Name" from IIS for TargetSite DirectoryEntry entry = new DirectoryEntry("IIS://LocalHost/" + targetSite); string friendlySiteName = entry.Properties["ServerComment"].Value.ToString(); // Open Application's Web.Config Configuration config = WebConfigurationManager.OpenWebConfiguration("/" + targetVDir, friendlySiteName); // Add new connection string setting for web.config ConnectionStringSettings appDatabase = new ConnectionStringSettings(); appDatabase.Name = DATABASE_CONNECTION_KEY; appDatabase.ConnectionString = connectionString; config.ConnectionStrings.ConnectionStrings.Clear(); config.ConnectionStrings.ConnectionStrings.Add(appDatabase); // Persist web.config settings config.Save(); }my errors are that "WebConfigurationManager" and "DATABASE_CONNECTION_KEY" don't exist in current context do i need to add additional assembly references and if so which ones? I'm not used to creating web deployment projects but i think this is one of my last steps, would appreciate any help.
Thanks
SanjitN
Participant
1734 Points
319 Posts
Re: Modifying connection String in Web config using Install Wizard
Feb 12, 2010 06:45 AM|LINK
DATABASE_CONNECTION_KEY means you need to add your DATABASE Connection String there.
Something like this
Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;
Replace DATABASE_CONNECTION_KEY with a similar string.
And for WebConfigurationManager try ading System.Web assembly
using System.Web;
Give a man a function() and you fix him for a day. Teach a man to code the function() and you fix him up for a lifetime.
Please mark as Answered if the post helps you.