我正在尝试将LocalDb与NEventStore一起使用,但即使我认为我已经正确设置了数据库,我仍然会收到以下异常:CCD_ 1。
在代码中,我将NEventStore配置为使用如下数据库:
this.EventStore = Wireup.Init()
.LogToOutputWindow()
.UsingInMemoryPersistence()
.UsingSqlPersistence("DefaultConnection")
.WithDialect(new MsSqlDialect())
.UsingJsonSerialization()
.LogToOutputWindow()
.Build();
我的web.config文件中有以下数据库连接:
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)MSSQLLocalDB;AttachDbFilename=|DataDirectory|MyDatabase.mdf;Initial Catalog=MyDatabase;Integrated Security=True" providerName="System.Data.SqlClient" />
使用Visual Studio,我在Asp.net MVC 5项目的App_Data文件夹中添加了一个SqlServerDatabase(MyDatabase.mdf(。NEventStore似乎能够打开数据库(如果我从项目中删除MyDatabase.mdf,我会得到一个不同的异常(。但它似乎无法正确初始化数据库。当我浏览数据库时,在遇到错误消息后,我发现没有创建任何表。
更奇怪的是,如果这个文档是正确的,Snapshots
应该是制作的第二个表。因此,创建第一个似乎没有问题。
StorageUnavailable Exception 的完整堆栈跟踪
at NEventStore.Persistence.Sql.SqlDialects.PagedEnumerationCollection.OpenNextPage() in c:TeamCitybuildAgentwork38b1777f2112a252srcNEventStorePersistenceSqlSqlDialectsPagedEnumerationCollection.cs:line 200
at NEventStore.Persistence.Sql.SqlDialects.PagedEnumerationCollection.MoveToNextRecord() in c:TeamCitybuildAgentwork38b1777f2112a252srcNEventStorePersistenceSqlSqlDialectsPagedEnumerationCollection.cs:line 146
at NEventStore.Persistence.Sql.SqlDialects.PagedEnumerationCollection.System.Collections.IEnumerator.MoveNext() in c:TeamCitybuildAgentwork38b1777f2112a252srcNEventStorePersistenceSqlSqlDialectsPagedEnumerationCollection.cs:line 70
at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source)
at NEventStore.Persistence.Sql.SqlPersistenceEngine.GetSnapshot(String bucketId, String streamId, Int32 maxRevision) in c:TeamCitybuildAgentwork38b1777f2112a252srcNEventStorePersistenceSqlSqlPersistenceEngine.cs:line 225
at NEventStore.Persistence.PipelineHooksAwarePersistanceDecorator.GetSnapshot(String bucketId, String streamId, Int32 maxRevision) in c:TeamCitybuildAgentwork38b1777f2112a252srcNEventStorePersistencePipelineHooksAwarePersistanceDecorator.cs:line 45
at NEventStore.AccessSnapshotsExtensions.GetSnapshot(IAccessSnapshots accessSnapshots, String bucketId, Guid streamId, Int32 maxRevision) in c:TeamCitybuildAgentwork38b1777f2112a252srcNEventStoreAccessSnapshotsExtensions.cs:line 49
at CommonDomain.Persistence.EventStore.EventStoreRepository.GetSnapshot(String bucketId, Guid id, Int32 version) in c:TeamCitybuildAgentwork38b1777f2112a252srcNEventStoreCommonDomainPersistenceEventStoreEventStoreRepository.cs:line 147
at CommonDomain.Persistence.EventStore.EventStoreRepository.GetById[TAggregate](String bucketId, Guid id, Int32 versionToLoad) in c:TeamCitybuildAgentwork38b1777f2112a252srcNEventStoreCommonDomainPersistenceEventStoreEventStoreRepository.cs:line 54
at CommonDomain.Persistence.EventStore.EventStoreRepository.GetById[TAggregate](Guid id, Int32 versionToLoad) in c:TeamCitybuildAgentwork38b1777f2112a252srcNEventStoreCommonDomainPersistenceEventStoreEventStoreRepository.cs:line 44
at CapraLibraShop.DataModel.Repositories.UserAggregateRepository.UserWithEmailExists(EmailAddress emailAddress) in D:ProjectsC#CapraLibraShopCapraLibraShop.DataModelRepositoriesUserAggregateRepository.cs:line 22
at CapraLibraShop.Controllers.AccountController.Register() in D:ProjectsC#CapraLibraShopCapraLibraShopControllersAccountController.cs:line 55
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.Async.AsyncControllerActionInvoker.<BeginInvokeSynchronousActionMethod>b__39(IAsyncResult asyncResult, ActionInvocation innerInvokeState)
at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`2.CallEndDelegate(IAsyncResult asyncResult)
at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.End()
at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult)
at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3d()
at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f()
我在看了两分钟后就找到了答案。但由于我很难在谷歌上搜索这个答案,我想最好把答案放在这里,而不是删除这个问题。
我忘了初始化存储引擎。我忽略了它,因为它的语法很流畅。让NEventStore初始化数据库的正确方法是在选择数据库类型后包含InitializeStorageEngine
方法:
this.EventStore = Wireup.Init()
.LogToOutputWindow()
.UsingInMemoryPersistence()
.UsingSqlPersistence("DefaultConnection")
.WithDialect(new MsSqlDialect())
.InitializeStorageEngine() // The oh so important line!
.UsingJsonSerialization()
.LogToOutputWindow()
.Build();