I created a new model:
public class AuthorDatacontext : DbContext
{
public DbSet<Author> Authors { get; set; }
static AuthorDatacontext()
{
Database.SetInitializer(new DropCreateDatabaseIfModelChanges<AuthorDatacontext>());
}
}
A connection string:
<add name="MyLibrary.Models.AuthorDatacontext" connectionString="Data Source= (LocalDb)\v10.0; Integrated Security=SSPI; AttachDBFilename = |DataDirectory|\MyLibrary.Models.AuthorDatacontext.mdf" providerName = "System.Data.SqlClient" />
and i used it in my controller:
var db = new AuthorDatacontext();
db.Authors.Add(author);
db.SaveChanges();
I did it before, in another project and it worked fine. But now i receive an error, trying saving a new author:
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.
What am i doing wrong? If i delete the connection and leave only the default connection, everything works fine.
The previous project had the same connection string:
<add name="MvcAuction.Models.AuctionsDataContext" connectionString="Data Source= (LocalDb)\v10.0; Integrated Security=SSPI; AttachDBFilename = |DataDirectory|\MvcAuction.Models.AuctionsDataContext.mdf" providerName = "System.Data.SqlClient" />