【问题标题】:defaultConnectionFactory defined in several projects几个项目中定义的defaultConnectionFactory
【发布时间】:2017-10-24 17:15:33
【问题描述】:

我收到了几个托管在 Azure 云中的 ASP.NET 项目:

AzureCommon——基于EntityFramework的sql代码,

AzureDashboard - 网站的服务器代码。

每个项目都有 app.config (web.config) 文件并定义了它自己的 sql 连接设置。运行代码时使用了哪些连接设置?是否在生产代码中使用 localdb?

AzureCommon App.config:

<entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="mssqllocaldb" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>

AzureDashboard web.config:

<configSections>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxx" requirePermission="false" />
  </configSections>
  <connectionStrings>
    <add name="MyDashboardConnection" connectionString="Server=tcp:xxxxxxx.database.windows.net,1433;Initial Catalog=MyDashboard;Persist Security Info=False;User ID=Myadmin;Password=xxxxxxx;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;" providerName="System.Data.SqlClient" />
  </connectionStrings>
  ...
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>

【问题讨论】:

    标签: c# sql database-connection


    【解决方案1】:

    在这种情况下,DbContext 的默认构造函数使用连接字符串参数。未使用 localdb。

    public partial class MyDashboardContext : IdentityDbContext<ApplicationUser>
        {
            public MyDashboardContext()
                : base("name=MyDashboardConnection")
            {
            }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-29
      • 1970-01-01
      • 2021-05-28
      • 2014-12-20
      相关资源
      最近更新 更多