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>
Related
With the following NuGet.Config file, I'm getting this error message during a docker container build:
What's the correct way to setup NuGet.Config?
/usr/share/dotnet/sdk/2.1.104/NuGet.targets(104,5): error : Unable to load the service index for source https://mycompany.pkgs.visualstudio.com/_packaging/myfeed/nuget/v3/index.json. [/src/Grains.sln]
/usr/share/dotnet/sdk/2.1.104/NuGet.targets(104,5): error : Response status code does not indicate success: 401 (Unauthorized). [/src/Grains.sln]
I have not setup the authorization for the private nuget feed correctly.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="NuGet" value="https://api.nuget.org/v3/index.json" />
<add key="MyCompany" value="https://mycompany.pkgs.visualstudio.com/_packaging/myfeed/nuget/v3/" />
</packageSources>
<!-- Used to store credentials -->
<packageSourceCredentials />
<apikeys>
<add key="https://mycompany.pkgs.visualstudio.com/_packaging/myfeed/nuget/v3/index.json" value="mytoken" />
</apikeys>
</configuration>
I got it working with this format:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="MyFeed" value="https://mycompany.pkgs.visualstudio.com/_packaging/myfeed/nuget/v3/index.json" />
</packageSources>
<packageSourceCredentials>
<MyFeed>
<add key="Username" value="myemailid" />
<add key="ClearTextPassword" value="mytoken" />
</MyFeed>
</packageSourceCredentials>
</configuration>
Suppose I have in a web app's root web.config:
<appSettings>
<add key="TestKey" value="TestValue0" />
...
How do I override that value in a sub folder of the same website?
You simply remove it and add it again:
<appSettings>
<remove key="TestKey" />
<add key="TestKey" value="TestValue0" />
...
I have got a Web.Release.config that is successfully transforming a connection string.
When I add a microsoft.identityModel section I get a warning saying
The 'http://schemas.microsoft.com/XML-Document-Transform' attribute is
not declared
And the transform doesnt work on that section.
What am I missing to get the transform to work?
Complete Web.Release.config here
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<connectionStrings>
<add name="MYNAME"
connectionString="metadata=res://*/Models.MYCOMPANY-Sales-Demo.csdl|res://*/Models.MYCOMPANY-Sales-Demo.ssdl|res://*/Models.MYCOMPANY-Sales-Demo.msl;provider=System.Data.SqlClient;provider connection string="data source=.;initial catalog=MYCOMPANYDemo;UID=MYCOMPANYDBUser;Password=********;multipleactiveresultsets=True;App=EntityFramework""
xdt:Transform="SetAttributes" xdt:Locator="Match(name)" />
</connectionStrings>
<system.web>
<compilation xdt:Transform="RemoveAttributes(debug)" />
</system.web>
<microsoft.identityModel>
<service>
<audienceUris>
<add value="http://MYCOMPANY-sales-demo.cloudapp.net/" xdt:Transform="Replace"/>
</audienceUris>
<federatedAuthentication>
<wsFederation realm="http://MYCOMPANY-sales-demo.cloudapp.net/" xdt:Transform="SetAttributes(realm)" />
</federatedAuthentication>
</service>
</microsoft.identityModel>
</configuration>
I've run into this also but have gotten it to work. What I did was a "RemoveAll" and an "Insert" instead of a replace/match:
<audienceUris>
<add xdt:Transform="RemoveAll" />
<add value="http://example.com/" xdt:Transform="Insert" />
</audienceUris>
When I do it that way I get the desired transform and output config file.
This appears to be working now with Visual Studio 2012 (v4.5.50709). I still get the 'attribute is not declared' warning in the editor, but the xdt:Transform="Replace" directive is working for me.
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.
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>