2

This row causes the exception:

var query = from customer in ctx.Customers select customer; 

Exception:

An unhandled exception of type 'System.Data.Entity.Core.ProviderIncompatibleException' occurred in EntityFramework.dll

An error occurred while getting provider information from the database. This can be caused by Entity Framework using an incorrect connection string. Check the inner exceptions for details and ensure that the connection string is correct.

Connection string from Database.Connection.ConnectionString:

Data Source=.\SQLEXPRESS;Initial Catalog=Customer.CustomersContext;Integrated Security=True;MultipleActiveResultSets=True 

App.config:

<?xml version="1.0" encoding="utf-8"?> <configuration> <entityFramework> <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework"> <parameters> <parameter value="v11.0" /> </parameters> </defaultConnectionFactory> </entityFramework> <connectionStrings> <add name="Customer.CustomersContext" providerName="System.Data.SqlClient" connectionString="Data Source=(localdb)\Projects;Initial Catalog=master;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False" /> </connectionStrings> </configuration> 

Context class:

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Data.Entity; namespace Customer { class CustomersContext : DbContext { public CustomersContext() : base("Customer.CustomersContext") { System.Console.WriteLine(Database.Connection.ConnectionString); } public DbSet<CustomerDb> Customers { get; set; } public DbSet<Contact> Contacts { get; set; } } } 

You can see I even tried to pass connection string name from app.config to context constructor (localdb should be used), but the printed connection string is still SQLExpress.

2
  • This is might will be helpful for you stackoverflow.com/questions/18355803/… Commented May 7, 2014 at 8:36
  • I think you need to configure the SqlConnectionFactory as opposed to the LocalDbConnectionFactory, which uses a slightly different connection string format. Commented May 7, 2014 at 9:05

1 Answer 1

1

Have a look at this. If you are using localdb, you need to accordingly change your connection string. So, your connection string should be Data Source=(localdb)\v11.0;Integrated Security=true;AttachDbFileName=C:\Path-to-your-database.mdf

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.