简体   繁体   中英

Entity Framework crashed Visual Studio 2015?

I just added EntityFramework to my MVC5 project. I`ve created classes and set up the connections string:

<connectionStrings>
  <add name="UserDBContext" 
       connectionString="server=.; database = DDP; integrated security = true;"
       providerName="System.Data.SqlClient"/>
</connectionStrings>

After debug Visual Studio is not responding and I have to remove it by Task Manager. I canot even debug to see what`s happen. What could do that ?

UPDATE

  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework"></defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
  <connectionStrings>
    <add name="UserDBContext" connectionString="Data Source=.; Integrated Security=True; Initial Catalog = DDP;" 
         providerName="System.Data.SqlClient" />
  </connectionStrings>
</configuration>

You used wrong connection string in your web.confing in you case it looks like code for SqlConnection.ConnectionString when it is used from C# directly.

But in ASP.NET MVC with EF connection string in web.confing looks different, where you use Data Source instead of server and Initial Catalog instead of database , so in the end you connection string will look something like that:

<add name="UserDBContext" connectionString="Data Source=SERVERNAME\SQLEXPRESS;Initial Catalog=DDP;Integrated Security=True" providerName="System.Data.SqlClient" />

Update

Put your <add ../> on 1 line, move Initial Catalog before Integrated Security and then delete ; after Integrated Security=True like below:

 <add name="UserDBContext" connectionString="Data Source=.;Initial Catalog=DDP;Integrated Security=True" providerName="System.Data.SqlClient" />

If this code doesn't work, then if you installed SQL Server Express with default settings use .\\SQLEXPRESS instead of . :

<add name="UserDBContext" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=DDP;Integrated Security=True" providerName="System.Data.SqlClient" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM