Entityframework does not recognize Config Web transformation

Asked

Viewed 352 times

2

In my solution C#, I use transformation Web.config to connect a specific data environment, but I’m having a problem with EntityFramework who can’t recognize string de conexão transformed, only recognizes the Web.config leading.

How to solve this problem?

Example of codes below:

Filing cabinet web.config

<connectionStrings>     
    <add name="ConexCobranca" connectionString="Data Source=BBBBBBB;Initial Catalog=CapCob;User ID=xxxyyy;Password=xxx" providerName="System.Data.SqlClient" />
    <add name="DbCobCapEntidades" connectionString="metadata=res://*/ModeloCobranca.csdl|res://*/ModeloCobranca.ssdl|res://*/ModeloCobranca.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=BBBBBBB;initial catalog=CapCob;persist security info=True;user ID=xxxyyy;password=xxx;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>

Filing cabinet web.HML.config

<?xml version="1.0" encoding="utf-8"?>

<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <connectionStrings>
    <add name="ConexCobranca" connectionString="Data Source=ABCDEF;Initial Catalog=CapCob;User ID=USERA;Password=xxx" xdt:Transform="SetAttributes(connectionString)" xdt:Locator="Match(name)" />
    <add name="DbCobEntidades" connectionString="metadata=res://*/ModeloCobranca.csdl|res://*/ModeloCobranca.ssdl|res://*/ModeloCobranca.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=ABCDEF;initial catalog=CapCob;persist security info=True;user ID=USERA;password=xxx;MultipleActiveResultSets=True;App=EntityFramework&quot;" xdt:Transform="SetAttributes(connectionString)" xdt:Locator="Match(name)" />
  </connectionStrings>

  <system.web>
    <compilation xdt:Transform="RemoveAttributes(debug)" />
  </system.web>
</configuration>

Cobranca.EDMX

public partial class DbCobEntidades : ObjectContext
{
        #region Constructors

        /// <summary>
        /// Initializes a new DbCobEntidades object using the connection string found in the 'DbCobEntidades' section of the application configuration file.
        /// </summary>
        public DbCobEntidades() : base("name=DbCobEntidades", "DbCobEntidades")
        {
            this.ContextOptions.LazyLoadingEnabled = true;
        }
        ...
}
  • 2

    Post your Webconfig, Code you have in your project!

  • 1

    @Virgilionovic posted it!

1 answer

0

In the archive web.HML.config, would be in case a configuration file of your application when a publication (compilation) of your project was generated, then when a compilation was generated from that web.HML.config, a Web.config with the specifications of web.HML.config.

According to the link:

Save and close the transformation file.

When you deploy the Webapp using selected build configuration and using a publication deployment package with one click, Web.config file is transformed according to your specifications.

Reference: How to: Transform Web.config when deploying a Web application project

In this same text says that Visual Studio creates a default configuration file for Debug and Release, but, nothing prevents it to be created its own, but, that this is only modified when generated a build of the project with the choice of the configuration file of Visual Studio(Web.config) or some other file created by the developer.

To make a publication of your project right-click on the name of your project and select under menu Publish and follow the step by step.

inserir a descrição da imagem aqui

In the tests run, it doesn’t really work, but when I managed to compile the project (Publish) I realized that he did the transformation to Web.Config that I selected.

The additional created files, served then, as configuration for example for a particular server that has connection to a different bank than the one on the local development machine being useful already since the database configuration when we create the pages are almost never equal of the server, would be a way of creating according to the server used.

Links:

Browser other questions tagged

You are not signed in. Login or sign up in order to post.