0

我正在使用visual studio 2010 mvc3,模型优先方法,我的连接字符串不断中断这是它带来的错误:

初始化数据库时发生异常。有关详细信息,请参阅 InnerException。

下面是它所在的代码:

public IEnumerable<Show> GetShows()
{
    return context.Shows.ToList();
}

以下是异常详细信息:

System.Data.DataException was unhandled by user code
  Message=An exception occurred while initializing the database. See the InnerException for details.
  Source=EntityFramework
  StackTrace:
       at System.Data.Entity.Internal.InternalContext.PerformInitializationAction(Action action)
       at System.Data.Entity.Internal.InternalContext.PerformDatabaseInitialization()
       at System.Data.Entity.Internal.LazyInternalContext.<InitializeDatabase>b__4(InternalContext c)
       at System.Data.Entity.Internal.RetryAction`1.PerformAction(TInput input)
       at System.Data.Entity.Internal.LazyInternalContext.InitializeDatabaseAction(Action`1 action)
       at System.Data.Entity.Internal.LazyInternalContext.InitializeDatabase()
       at System.Data.Entity.Internal.InternalContext.Initialize()
       at System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType)
       at System.Data.Entity.Internal.Linq.InternalSet`1.Initialize()
       at System.Data.Entity.Internal.Linq.InternalSet`1.GetEnumerator()
       at System.Data.Entity.Infrastructure.DbQuery`1.System.Collections.Generic.IEnumerable<TResult>.GetEnumerator()
       at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
       at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
       at TheatreGroup.DAL.ShowRepository.GetShows() in E:\TheatreGroupProject\BackUpWEb28.03.2012\TheatreGroupProject\TheatreGroup\TheatreGroup\DAL\ShowRepository.cs:line 20
       at TheatreGroup.Controllers.ShowsController.Index(String sortOrder, String currentFilter, String searchString, Nullable`1 page) in E:\TheatreGroupProject\BackUpWEb28.03.2012\TheatreGroupProject\TheatreGroup\TheatreGroup\Controllers\ShowsController.cs:line 46
       at lambda_method(Closure , ControllerBase , Object[] )
       at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters)
       at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
       at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
       at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12()
       at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation)
  InnerException: System.Data.EntityException
       Message=The underlying provider failed on Open.
       Source=System.Data.Entity
       StackTrace:
            at System.Data.EntityClient.EntityConnection.OpenStoreConnectionIf(Boolean openCondition, DbConnection storeConnectionToOpen, DbConnection originalConnection, String exceptionCode, String attemptedOperation, Boolean& closeStoreConnectionOnFailure)
            at System.Data.EntityClient.EntityConnection.Open()
            at System.Data.Objects.ObjectContext.EnsureConnection()
            at System.Data.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption)
            at System.Data.Objects.ObjectQuery`1.System.Collections.Generic.IEnumerable<T>.GetEnumerator()
            at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source)
            at System.Data.Objects.ELinq.ObjectQueryProvider.<GetElementFunction>b__1[TResult](IEnumerable`1 sequence)
            at System.Data.Objects.ELinq.ObjectQueryProvider.ExecuteSingle[TResult](IEnumerable`1 query, Expression queryRoot)
            at System.Data.Objects.ELinq.ObjectQueryProvider.System.Linq.IQueryProvider.Execute[S](Expression expression)
            at System.Data.Entity.Internal.Linq.DbQueryProvider.Execute[TResult](Expression expression)
            at System.Linq.Queryable.FirstOrDefault[TSource](IQueryable`1 source)
            at System.Data.Entity.Internal.InternalContext.QueryForModelHash()
            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 context)
            at System.Data.Entity.Database.<>c__DisplayClass2`1.<SetInitializerInternal>b__0(DbContext c)
            at System.Data.Entity.Internal.InternalContext.<>c__DisplayClass5.<PerformDatabaseInitialization>b__3()
            at System.Data.Entity.Internal.InternalContext.PerformInitializationAction(Action action)
       InnerException: System.Data.SqlClient.SqlException
            Message=Database 'E:\TheatreGroupProject\BackUpWEb28.03.2012\TheatreGroupProject\TheatreGroup\TheatreGroup\App_Data\StudentTheatre.mdf' already exists. Choose a different database name.
Cannot attach the file 'K:\Year 3 Web Programming\AnotherWebProject\BackUpWEb28.03.2012\TheatreGroupProject\TheatreGroup\TheatreGroup\App_Data\projecttheatre.mdf' as database 'YourCatalog'.
            Source=.Net SqlClient Data Provider
            ErrorCode=-2146232060
            Class=16
            LineNumber=65536
            Number=1801
            Procedure=""
            Server=\\.\pipe\C8A38AE3-00CC-42\tsql\query
            State=2
            StackTrace:
                 at System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject)
                 at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)
                 at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
                 at System.Data.SqlClient.SqlConnection.Open()
                 at System.Data.EntityClient.EntityConnection.OpenStoreConnectionIf(Boolean openCondition, DbConnection storeConnectionToOpen, DbConnection originalConnection, String exceptionCode, String attemptedOperation, Boolean& closeStoreConnectionOnFailure)
            InnerException: 
4

0 回答 0