2014-03-18 58 views
2

我在VS2012上启动了一个MVC项目,创建了我的模型,我的控制器和我的视图。我首先使用实体​​框架代码,所以我启用了迁移,并根据代码中的更改相应更新数据库。 页面运行正常,数据库正常工作,数据正在被检索,因此它的功能,一切都很好。SQL Server对象资源管理器不显示我的数据库

的问题是,我看到在我的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,但我的对象浏览器中的服务器已经是正确的了。

回答

0

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

正如你的web.config,我发现

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

你的程序可以使用这个默认连接来连接数据库。

当您安装EF Nuget Package时,可能已经设置了默认连接。

欲了解更多有关默认连接工厂,看看http://msdn.microsoft.com/en-au/data/jj556606.aspx#Factory

+0

没错,就是这样,谢谢你的提示。 –

相关问题