Config Transform does not work? - visual-studio-2010

I have this config in my Web.config file:
<connectionStrings>
<add name="LocalConnString" connectionString="metadata=res://*/;provider=System.Data.SqlClient;provider connection string="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\NCU.Joberwocky.Db.mdf;Integrated Security=True;User Instance=True;MultipleActiveResultSets=True"" providerName="System.Data.EntityClient" />
</connectionStrings>
This in my Web.Release.config:
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<connectionStrings>
<add name="LocalConnString" connectionString="metadata=res://*/;provider=System.Data.SqlClient;provider connection string="Data Source=192.168.10.3;Initial Catalog=AeorionJobs;User Id=aeorionjobs;Password=aejobs3695;MultipleActiveResultSets=True""
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
</connectionStrings>
</configuration>
When I switch the build to release, it still uses the config from Web.config. Any idea what the problem is?

I am also struggling with configuration transforms. Actually I am trying to have a different configuration on my environment than the common one uploaded in code control.
I have been also trying the same thing as you are doing and I would say those transforms are only applied on the deployment packages that you can build.
Hope it helps.

Related

Java XPath Prefix must resolve to a namespace

I'm having difficulty getting my XPath expression to work with Java. I am using XPath 1.0.
If I use https://www.freeformatter.com/xpath-tester.html the following works:
/*:configuration/*:connectionStrings/*:add[#*:name= 'Data.Server.ConnectionString']/#name
When I try the same in my java program, it gives me:
com.sun.org.apache.xpath.internal.domapi.XPathStylesheetDOM3Exception: Prefix must resolve to a namespace:
I tried replacing the : with local-name() since I'm using XPath 1.0 but had no luck.
Here's the source document
<?xml version="1.0" encoding="UTF-8" standalone="no"?><configuration>
<configSections>
<sectionGroup name="telerik.web.ui">
<section allowDefinition="MachineToApplication" name="radCompression" requirePermission="false" type="Telerik.Web.UI.RadCompressionConfigurationSection, Telerik.Web.UI, PublicKeyToken=121fae78165ba3d4"/>
</sectionGroup>
</configSections>
<telerik.web.ui>
<radCompression enablePostbackCompression="true"/>
</telerik.web.ui>
<appSettings>
<add key="InfrastructureConfig.Server" value="[App.BaseDirectory]\infrastructure.config"/>
<add key="InfrastructureConfig.Debug" value="[App.BaseDirectory]\Infrastructure.config"/>
<add key="ValidationSettings:UnobtrusiveValidationMode" value="None"/>
<add key="Telerik.ScriptManager.TelerikCdn" value="Disabled"/>
<add key="Telerik.StyleSheetManager.TelerikCdn" value="Disabled"/>
<add key="vs:EnableBrowserLink" value="false"/>
</appSettings>
<connectionStrings>
<add connectionString="data source=[DB.Instance.Name];persist security info=True;user id=[DB.UserName];password=[DB.Password]" name="Data.Server.ConnectionString"/>
<add connectionString="data source=[DB.Instance.Name];persist security info=True;user id=[DB.UserName];password=[DB.Password]" name="Data.Debug.ConnectionString"/>
</connectionStrings>
</configuration>
I need to return connectionString and name.
Any ideas?
Thanks!
The syntax *:xxx requires XPath 2.0+. Upgrade to an XPath 2.0 processor (there are several available in the Java world), or if you must, use the workaround *[local-name()='xxx'].
One shortest (but less secure) way to grab this could be :
//*[#connectionString and #name]/#*
If you face an error, use :
//*[#connectionstring and #name]/#*

Web.config Remove ConnectionStrings node from Web.Release.Config

I have this in my Web.config so that my service will run locally:
<connectionStrings>
<add name="DefaultConnection" providerName="System.Data.SqlClient" connectionString="Data Source=IPADD;Initial Catalog=DB;Persist Security Info=True;User ID=UN;Password=PW" />
</connectionStrings>
I need this here because the Web.Debug.Config doesn't work. So when I publish I want to remove this string because it is actually inherited from a parent Web.config
<connectionStrings>
<remove name="DefaultConnection"/>
</connectionStrings>
This doesn't seem to work... (it throws a The entry 'DefaultConnection' has already been added. error)
How can I remove it? XSLT?
P.s. I can't use clear/ because it removes the Machine.Config DB Connection string to the Membership provider also throwing a different error
Put below code:
<connectionStrings>
<add name="LocalizationDB"
xdt:Transform="Remove" xdt:Locator="Match(name)"/>
</connectionStrings>
But be careful when you do publish from visual studio. When you look on Output view. It should write you something like:
Transformed Web.config using Web.Release.config into obj\Debug\TransformWebConfig\transformed\Web.config.
Copying all files to temporary location below for package/publish:
But if you have active "Debug" you will have Web.Debug.config instead of Web.Release.config

asp.net mvc 3: web.config is not being read?

I created a link to my web.config which is defnined as a central config file defined at solution level. So the project I am having troubles contains a reference to this config file:
web.config:
<configuration>
<connectionStrings>
<add name="NorthwindEntities" connectionString="metadata=res://*/NWind.csdl|res://*/NWind.ssdl|res://*/NWind.msl;provider=System.Data.SqlClient;provider connection string="data source=.\SQLEXPRESS;initial catalog=Northwind;integrated security=True;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
</configuration
Also I created a .edmx file and the connectionstring is like:
<configuration>
<connectionStrings>
<add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient" />
<add name="NorthwindEntities" connectionString="metadata=res://*/NWind.csdl|res://*/NWind.ssdl|res://*/NWind.msl;provider=System.Data.SqlClient;provider connection string="data source=.\SQLEXPRESS;initial catalog=Northwind;integrated security=True;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
</configuration>
The issue is that my .edmx file wont read the connectionstring:
I am getting an error:
Object reference not set to an instance of an object?
string constrng = ConfigurationManager.ConnectionStrings["NorthwindEntities"].ToString();

Server specific Web.config replacement

I am currently using Visual Studio 2010. I want to set up a different connection string for my "Testing" Configuration. I have tried doing it by using config transformations, but it does not seem to work.
In my Web.config my connection string is the following:
<add name="MyDb" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=DevelopmentDb;Integrated Security=SSPI; MultipleActiveResultSets=True" providerName="System.Data.SqlClient" />
I found out that you can replace the connection string defined in Web.config by adding config transformation. I right clicked on Web.config and clicked on "Add config transformations". This created a Web.TEST.config file. I then added a connection string replacement, but it doesnt seem to work. It still uses the connection string defined in Web.config.
The file contents of Web.TEST.config is:
<?xml version="1.0"?>
<!-- For more information on using web.config transformation visit http://go.microsoft.com/fwlink/?LinkId=125889 -->
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<!--
In the example below, the "SetAttributes" transform will change the value of
"connectionString" to use "ReleaseSQLServer" only when the "Match" locator
finds an atrribute "name" that has a value of "MyDB".
-->
<connectionStrings>
<add name="MyDb"
connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=TestDb;Integrated Security=SSPI; MultipleActiveResultSets=True"
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
</connectionStrings>
<system.web>
<!--
In the example below, the "Replace" transform will replace the entire
<customErrors> section of your web.config file.
Note that because there is only one customErrors section under the
<system.web> node, there is no need to use the "xdt:Locator" attribute.
<customErrors defaultRedirect="GenericError.htm"
mode="RemoteOnly" xdt:Transform="Replace">
<error statusCode="500" redirect="InternalError.htm"/>
</customErrors>
-->
</system.web>
</configuration>
Any ideas to what I could be missing?
Transformations get applied when you deploy the project, not when you compile it.
If you are using IIS, you can deploy to the configured web application directory, which will cause the transform to apply.

VS2010 Build Deployment Package web.release.config transform error

I am getting the transformed web.config in the deployment package incorrectly transformed.
The result is as follows (notice how the connection string gets generated):
<connectionStrings>
<add name="xxxConnectionStringNamexxx"
connectionString="$(ReplacableToken_xxxConnectionStringNamexxx-Web.config Connection String_0)" providerName="System.Data.SqlClient" />
</connectionStrings>
Web.Config:
<connectionStrings>
<add name="xxxConnectionStringNamexxx"
connectionString="Data Source=.\sqlexpress2005;Initial Catalog=xxxx;Integrated Security=True" providerName="System.Data.SqlClient" />
</connectionStrings>
Web.Release.config:
<connectionStrings>
<add name="xxxConnectionStringNamexxx" connectionString="Data Source=.\sqlexpress2005;Initial Catalog=xxxx;Integrated Security=True" providerName="System.Data.SqlClient" xdt:Transform="SetAttributes(connectionString)" xdt:Locator="Match(name)"/>
</connectionStrings>
Any ideas?
Thanks
So benoit found an answer on the asp.net forums : ReplacableToken_ when using web.config transform? .
I deployed to a folder on my desktop and the web.config file was transformed correctly.

Resources