【问题标题】:SQL Server Object Explorer doesn't show my databaseSQL Server 对象资源管理器不显示我的数据库
【发布时间】:2014-03-18 22:24:19
【问题描述】:

我在 VS2012 上启动了一个 MVC 项目,创建了我的模型、控制器和视图。我首先使用实体​​框架代码,所以我启用了迁移,并且我正在根据代码中的更改更新数据库。 页面运行正常,数据库正常工作,数据正在按应有的方式检索,所以从功能上来说,一切都很好。

问题是我在 web.config 中看不到连接字符串:

<?xml version="1.0" encoding="utf-8"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=301880
  -->
<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <appSettings>
    <add key="webpages:Version" value="3.0.0.0" />
    <add key="webpages:Enabled" value="false" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />
  </system.web>
  <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>
</configuration>

数据库也没有显示在 SQL Server 对象资源管理器中... 我已经检查了this answer,但我的对象资源管理器上的服务器已经是正确的。

【问题讨论】:

    标签: c# asp.net asp.net-mvc entity-framework ef-code-first


    【解决方案1】:

    我认为你是使用默认连接工厂连接的,它允许程序仅在配置文件中没有指定连接字符串时定位数据库。

    在您的 web.config 中,我发现

    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
    

    您的程序可能正在使用此默认连接来连接数据库。

    安装 EF Nuget 包时可能已设置默认连接。

    有关默认连接工厂的更多信息,请查看http://msdn.microsoft.com/en-au/data/jj556606.aspx#Factory

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-08-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-23
      • 1970-01-01
      相关资源
      最近更新 更多