Web.config transform to change value - web-config

I'm working on a project where I need to include web.config transofrm to change a value depending if it's in the production environment or test environment.
Lets say for example that I want the value testItem to be in my test environment and the value prodItem to be in my production environment.
This is how I did it so far.
web.config:
<appSettings>
<add key ="ELeg" value ="testItem"/>
</appSettings>
Web.Prod.config:
<configuration>
<appSettings>
<add key ="prodItem"/>
</appSettings>
</configuration>
As you can see the code is similar but the only difference is that I changed the value in the web.Prod.config.
How do I use the web.config transform to correctly change the value in the production environment?

Related

Installing multiple Quartz.NET services on one machine

I'm using Quartz.NET 2.2.400.0 and am experiencing problems installing multiple instances on a single machine.
I am trying to amend the name of the instance via the configuration file (Quartz.Server.exe) as follows:
<quartz >
<add key="quartz.checkConfiguration" value="false"/>
<add key="quartz.server.serviceName" value="CalSched"/>
<add key="quartz.server.serviceDisplayName" value="CalSched"/>
<add key="quartz.server.serviceDescription" value="CalSchedservice"/>
</quartz>
When running Quartz.Server.exe install without the above, everything works perfectly. When the service name is specified, the scheduler does not run.
I wondered if anybody would be able to shed any light on this?
This is an old thread. But I will put the answer here in case someone got same issue. When <quartz> tag (Quartz.Server.exe.config) is used, quartz will ignore configurations in quartz.config and therefore, this configuration line is ignored quartz.plugin.xml.fileNames = ~/quartz_jobs.xml. As a result, quartz won't read your job settings and won't run the job as expected.
So you need to move all your configuration to tag. You need to add
<quartz >
<add key="quartz.checkConfiguration" value="false"/>
<add key="quartz.server.serviceName" value="CalSched"/>
<add key="quartz.server.serviceDisplayName" value="CalSched"/>
<add key="quartz.server.serviceDescription" value="CalSchedservice"/>
<!-- MUST ADD -->
<add key="quartz.plugin.xml.type" value="Quartz.Plugin.Xml.XMLSchedulingDataProcessorPlugin, Quartz" />
<add key="quartz.plugin.xml.fileNames" value="~/quartz_jobs.xml" />
</quartz>
And it will work.

EF4 The provider did not return a Provider Manifest Token string

Yes, one more question about Provider manifest token. Unfortunately all previous 22 questions was not useful to solve my problem. I developing simple web application using MVC4 + Code First + Sql Express.
Here is my context descendant:
public class MCQContext : DbContext
{
public MCQContext()
: base("name=ApplicationConnection")
{
}
...............
}
And here - part of web.config related to the problem:
<configuration>
<configSections>
<section name="entityFramework"
type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
requirePermission="false" />
</configSections>
<connectionStrings>
<add name="ApplicationConnection"
connectionString="Data Source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true"
providerName="System.Data.SqlClient" />
</connectionStrings>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework">
<parameters>
<parameter value="name=ApplicationConnection" />
</parameters>
</defaultConnectionFactory>
</entityFramework>
So, as you can see, correct connection string passed to base of context class (I got the same error if I rename connection string to "MCQContext" and do not pass anything to parent context class).
I have no idea how to fix it. This behavior reproduced if I creating absolutely empty MVC4 application, remove all packages (I prefer manually specify required assemblies and do not use NuGet) and fix references (including reference to sqlserver express).
The problem with your connection string here is:
<add name="TrempimModel"
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;
AttachDBFilename=|DataDirectory|aspnetdb.sdf;
User Instance=true"
providerName="System.Data.SqlClient" />
You're basically defining what "server" you're connecting to - but you're not saying what database inside the file to connect to. Also - the file extension for SQL Server Express database files is .mdf (not .sdf - that's SQL Server Compact Edition) - you need to take that into account, too! (was a typo, according to comment by OP).
You need to define an extra database=.... (or Initial Catalog=.....) in your connection string:
<add name="TrempimModel"
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;
database=YourDatabaseName;
AttachDBFilename=|DataDirectory|aspnetdb.mdf;
User Instance=true"
providerName="System.Data.SqlClient" />
Then it should work just fine.

Web.Debug.Config with different connection strrings

I have a Web.config file and a Web.Debug.Config file. My Web.Debug.Config file is practically empty and I would like to add to it a connectionstrings section to override the one in the Web.Config file. I tried just adding the connectionstrings section in the config file but it didn't pick it up. I know there are some commands I need to use in one or both config files but am not sure what they are. Can someone help me out please?
Thanks,
Sachin
You should be able to do the following (not tested, but should work) to replace the Web.Config file's connectionStrings section:
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<connectionStrings xdt:Transform="Replace">
<add name="AuthenticationDatabase" connectionString="connection-string-here" providerName="System.Data.SqlClient" />
<add name="OtherDatabase" connectionString="connection-string-here" providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>
If you're just looking to update an existing connectionString:
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<connectionStrings>
<add xdt:Transform="SetAttributes" xdt:Locator="Match(name)" name="AuthenticationDatabase" connectionString="new-string-here" providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>

Web.config Transform

I have a config that has multiple connection strings. They all point to the same database server. Is there a way to replace a portion of the web.config, i.e.
<connectionStrings>
<add name="Conn1" connectionString="...DataSource=server1;Initial Catalog=DBName..." />
<add name="Conn2" connectionString="...DataSource=server1;Initial Catalog=DBName2..." />
</connectionStrings>
I want to change server1 with server 2. I could do this...
<add xdt:Transform="SetAttributes" xdt:Locator="Match(name)" name="Conn1" connectionString="...DataSource=server2;Initial Catalog=DBName..." />
<add xdt:Transform="SetAttributes" xdt:Locator="Match(name)" name="Conn2" connectionString="...DataSource=server2;Initial Catalog=DBName..." />
but wanted to see if there was a more all-inclusive way.
According the msdn documentation of web.config transformation there is no possibility for this kind of transformation. You can only do Replace, Insert, InsertBefore, InsertAfter, Remove, RemoveAll, RemoveAttributes and SetAttributes transformations.

Separate ConnectionStrings and mailSettings from web.config? Possible?

Is it possible to separate ConnectionStrings and mailSettings from web.config?
Devel environment has different IP addresses for connectionstrings and smtp mails because of development and testing. We dont want to do tests and devel using live machines and live IP addresses.
Is it possible?
I found the answer on MSDN:
<configuration>
<connectionStrings configSource="connections.config"/>
</configuration>
With file connections.config containing
<connectionStrings>
<add name="name" connectionString="conn_string" providerName="System.Data.SqlClient" />
<add name="name2" connectionString="conn_string2" providerName="System.Data.SqlClient" />
</connectionStrings>