美文网首页
新建CodeFirst EF工程时VS连接数据库问题

新建CodeFirst EF工程时VS连接数据库问题

作者: Angeladaddy | 来源:发表于2018-12-24 12:23 被阅读34次

VS中安装官网教程, 新建EF Codefirst 工程是时, 会生成以下配置:

<?xml version="1.0" encoding="utf-8"?>
<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>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
  </startup>
  <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>
</configuration>

从上面配置可以看出,不指定任何数据库的话, 默认是连接到localdb的, 那这个LocalDb在哪里?VS中怎么连接呢?

打开C:\Users\<USER NAME>\AppData\Local\Microsoft\Microsoft SQL Server Local DB\Instances\里面的文件夹名称就是你连接数据库的名称, 我的是mssqllocaldb

image.png
在服务器资源管理器中新建连接到这个名称就可以了:
image.png

相关文章

网友评论

      本文标题:新建CodeFirst EF工程时VS连接数据库问题

      本文链接:https://www.haomeiwen.com/subject/gxoakqtx.html