Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
407 views
in Technique[技术] by (71.8m points)

asp.net - EF 4.1 exception "The provider did not return a ProviderManifestToken string"

I am trying to replicate an example found on MSDN. I am using ASP.NET and EF 4.1 (CTP?). I've used NuGet to install the EntityFramework package.

I am getting this error: The provider did not return a ProviderManifestToken string ... and the database is never created.

Here is my connection string:

<add name="HospitalContext"
   connectionString=
   "data source=.SQLExpress;initial catalog=NewTestDB;integrated security=True;"
   providerName="System.Data.SqlClient"/>

Here is my code:

var pat = new Patient { Name = "Shane123132524356436435234" };
db.Patients.Add(pat);

var labResult = new LabResult { Result = "bad", Patient = pat };

int recordAffected = db.SaveChanges();

Here is my context:

public class HospitalContext : DbContext
{
    static HospitalContext()
    {
        Database.SetInitializer(new HostpitalContextInitializer());
    }

    public DbSet<Patient> Patients { get; set; }
    public DbSet<LabResult> LabResults { get; set; }
}

public class HostpitalContextInitializer :
             DropCreateDatabaseIfModelChanges<HospitalContext>
{
    protected override void Seed(HospitalContext context)
    {
        context.Patients.Add(new Patient { Name = "Fred Peters" });
        context.Patients.Add(new Patient { Name = "John Smith" });
        context.Patients.Add(new Patient { Name = "Karen Fredricks" });
    }
}

This is a fully patched SQL 2008 system, with VS 2010 SP1.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I was getting this error and tried a few of the earlier suggestions. Then I checked the Inner Exception and noticed I was getting a simple SQL login failure for the user. Just something else to check.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...