在几个项目

时间:2017-10-16 09:47:31

标签: c# sql database-connection

我在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>

1 个答案:

答案 0 :(得分:1)

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

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