ADO.NET EF - 无法连接到我的数据库(使用Visual Studio 2010)

时间:2013-02-12 13:06:14

标签: visual-studio-2010 ado.net-entity-data-model

所以我在这个问题上苦苦挣扎了4个多小时,我不知道在哪里再看。我在ADO.NET Entity Framework - [参见教程] [1] [1]:http://msdn.microsoft.com/en-us/data/jj193542中为绝对的初学者学习本教程 我正在使用Microsoft SQL Server 2012,我正在将此App.Config文件用于我的项目:

<?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=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="Data Source=sqlserver2012; Integrated Security=True; MultipleActiveResultSets=True" />
      </parameters>
    </defaultConnectionFactory>
  </entityFramework>
</configuration>

但我一直收到错误,当我使用此代码时,错误是:**An error occurred while getting provider information from the database. This can be caused by Entity Framework using an incorrect connection string.**

我对ADO.NET Entity Framework完全不熟悉,但我认为问题可能在defaultConnectionFactory配置中。但无论如何我无法找到如何继续以及如何解决这个问题。

1 个答案:

答案 0 :(得分:0)

如果您实际上在本地主机上有名为sqlserver2012的SQL Server实例,那么connectionString应该如下所示

<parameter value="Data Source=localhost\sqlserver2012; Integrated Security=True; MultipleActiveResultSets=True" />

干杯, 吨。