System.Daten.DataException Fehler aufgetreten EntityFramework.dll

Habe ich nach diesem tutorial Erste Schritte mit Entity Framework 6 Code First mit MVC 5.

Als ich zu dem Abschnitt, wo ich brauche, um das Programm auszuführen und klicken Sie auf die Schülerleistungen, so dass das Programm schaffen würde, die Datenbank bekomme ich folgende Fehlermeldung.

System.Daten.DataException Fehler aufgetreten EntityFramework.dll

System.Daten.DataException war unhandled by user code
HResult=-2146233087
Message=Ein Ausnahmefehler ist aufgetreten während der Initialisierung der Datenbank. Finden Sie die InnerException-für details.
Source=EntityFramework
StackTrace:
System.Daten.Entität.Intern.InternalContext.PerformInitializationAction(Aktion Aktion)
System.Daten.Entität.Intern.InternalContext.PerformDatabaseInitialization()
System.Daten.Entität.Intern.LazyInternalContext.b__4(InternalContext c)
System.Daten.Entität.Intern.RetryAction1.PerformAction(TInput input)
at System.Data.Entity.Internal.LazyInternalContext.InitializeDatabaseAction(Action
1 Aktion)
System.Daten.Entität.Intern.LazyInternalContext.InitializeDatabase()
System.Daten.Entität.Intern.InternalContext.Initialize()
System.Daten.Entität.Intern.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType)
System.Daten.Entität.Intern.Linq -.InternalSet1.Initialize()
at System.Data.Entity.Internal.Linq.InternalSet
1.GetEnumerator()
System.Daten.Entität.Infrastruktur.DbQuery1.System.Collections.Generic.IEnumerable<TResult>.GetEnumerator()
at System.Collections.Generic.List
1..ctor(IEnumerable1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable
1 Quelle)
bei ContosoUniversityFollow.Controller.StudentController.Index() in c:\Users\Office\Documents\Visual Studio 2013\Projects\ContosoUniversityFollow\ContosoUniversityFollow\Controller\StudentController.cs:Zeile 21
bei lambda_method(Schließung , ControllerBase , Object[] )
System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] Parameter)
System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary2 parameters)
at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary
2 Parameter)
System.Web.Mvc.Async.AsyncControllerActionInvoker.ActionInvocation.InvokeSynchronousActionMethod()
System.Web.Mvc.Async.AsyncControllerActionInvoker.b__36(IAsyncResult asyncResult, ActionInvocation innerInvokeState)
System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult2.CallEndDelegate(IAsyncResult asyncResult)
at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase
1.Ende()
System.Web.Mvc.Async.AsyncResultWrapper.Ende[TResult](IAsyncResult asyncResult, Object tag)
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult)
System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.b__3c()
bei System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<>c__DisplayClass45.b__3e()
InnerException: System.Daten.Entität.Core.EntityException
HResult=-2146233087
Message=Die zugrunde liegende Anbieter konnte nicht auf "Öffnen".
Source=EntityFramework
StackTrace:
System.Daten.Entität.Core.EntityClient.EntityConnection.Öffnen Sie()
System.Daten.Entität.Core.Objekte.ObjectContext.EnsureConnection()
bei System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess)
at System.Data.Entity.Core.Objects.ObjectQuery
1.<>c__DisplayClassb.b__9()
bei System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute[TResult](Func1 operation)
at System.Data.Entity.Core.Objects.ObjectQuery
1.GetResults(Nullable1 forMergeOption)
at System.Data.Entity.Core.Objects.ObjectQuery
1..GetEnumerator>b__0()
System.Faul1.CreateValue()
at System.Lazy
1.LazyInitValue()
System.Faul1.get_Value()
at System.Data.Entity.Internal.LazyEnumerator
1.MoveNext()
System.Linq -.Enumerable.FirstOrDefault[TSource](IEnumerable1 source)
at System.Data.Entity.Core.Objects.ELinq.ObjectQueryProvider.<GetElementFunction>b__1[TResult](IEnumerable
1 Folge)
System.Daten.Entität.Core.Objekte.ELinq.ObjectQueryProvider.ExecuteSingle[TResult](IEnumerable1 query, Expression queryRoot)
at System.Data.Entity.Core.Objects.ELinq.ObjectQueryProvider.System.Linq.IQueryProvider.Execute[TResult](Expression expression)
at System.Data.Entity.Internal.Linq.DbQueryProvider.Execute[TResult](Expression expression)
at System.Linq.Queryable.FirstOrDefault[TSource](IQueryable
1 Quelle)
System.Daten.Entität.Intern.EdmMetadataRepository.QueryForModelHash(Func2 createContext)
at System.Data.Entity.Internal.InternalContext.QueryForModelHash()
at System.Data.Entity.Internal.ModelCompatibilityChecker.CompatibleWithModel(InternalContext internalContext, ModelHashCalculator modelHashCalculator, Boolean throwIfNoMetadata)
at System.Data.Entity.Internal.InternalContext.CompatibleWithModel(Boolean throwIfNoMetadata)
at System.Data.Entity.Database.CompatibleWithModel(Boolean throwIfNoMetadata)
at System.Data.Entity.DropCreateDatabaseIfModelChanges
1.InitializeDatabase(TContext Kontext)
System.Daten.Entität.Intern.InternalContext.<>c__DisplayClasse1.<CreateInitializationAction>b__d()
at System.Data.Entity.Internal.InternalContext.PerformInitializationAction(Action action)
InnerException: System.Data.SqlClient.SqlException
HResult=-2146232060
Message=Cannot open database "ContosoUniversity1" requested by the login. The login failed.
Login failed for user 'Office-PC\Office'.
Source=.Net SqlClient Data Provider
ErrorCode=-2146232060
Class=11
LineNumber=65536
Number=4060
Procedure=""
Server=(LocalDb)\v11.0
State=1
StackTrace:
at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection)
at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource
1 wiederholen, DbConnectionOptions userOptions, DbConnectionInternal& Verbindungs -)
System.Daten.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource
1 wiederholen, DbConnectionOptions userOptions)
System.Daten.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource1 retry, DbConnectionOptions userOptions)
at System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource
1 retry)
System.Daten.SqlClient.SqlConnection.TryOpen(TaskCompletionSource1 retry)
at System.Data.SqlClient.SqlConnection.Open()
at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.<>c__DisplayClass1.<Execute>b__0()
at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute[TResult](Func
1-Betrieb)
System.Daten.Entität.SqlServer.DefaultSqlExecutionStrategy.Execute(Aktion, operation)
System.Daten.Entität.Core.EntityClient.EntityConnection.Öffnen Sie()
InnerException:

Ich habe eine harte Zeit versucht, das problem zu beheben. Ich habe alles befolgt und sogar wiederholen Sie es, nur um sicherzustellen, dass ich es richtig gemacht. Ich glaube nicht, dass ich irgendwelche Schritte. Aber es ist etwas falsch. Wenn ich das ganze sample code, funktioniert alles einwandfrei.

Jede Hilfe ist willkommen.

Dank,

Pheap

EDIT:

Es war wirklich frustrierend für eine so einfache Sache, die zu einem Fehler führen, wie diese.
@mmeasor, ich habe gerade gesehen, dass Fehler als gut. Es kann keine Verbindung zum Datenbank. So führen mich die Verbindung prüfen.

Was geschehen war, dass bei der ersten habe ich diesen connection string:
System.Daten.DataException Fehler aufgetreten EntityFramework.dll

So EntityFramework erstellt eine Datenbank-Datei ContosoUniversity1.mdf, hier wie C:\Users\Office\ContosoUniversity1.mdf. Aber dann will ich es anderes erstellen und verwenden, statt, und dieses mal will ich es in das Programm App_Data\ Ordner statt.

Also modifizierte ich die web.config-Datei:
System.Daten.DataException Fehler aufgetreten EntityFramework.dll

Ich dachte, wenn ich das mache, EF wird eine neue Datenbank zu erstellen, die für mich in der \App_Data\ Ordner und link, dass anstelle des alten in C:\Users\Office.

War ich so falsch! das war, wenn ich start immer den Fehler oben gepostet. Und ich kann nicht finden was das problem verursacht.

Mit dem zweiten web.config habe ich versucht, kopieren Sie die Datenbankdatei im App_Data-Ordner, aber das funktioniert immer noch nicht.

Nun benutze ich die ersten Verbindungs-string und es funktioniert gut.

Die Frage ist nun also: Wie werden die Programm-links für Datenbank-Datei in der \App_Data\ Ordner statt?

Dank,

Pheap

  • hat man sich bei der inneren Ausnahme? es sagt Fehler bei der Anmeldung für Office-PC\Office. stellen Sie sicher, dass Benutzer Zugriff auf die Datenbank hat, und, dass Sie das richtige Passwort
InformationsquelleAutor Pheap | 2014-03-21
Schreibe einen Kommentar