pjvds / ncqrs

Ncqrs Framework - The CQRS Framework for .NET
Other
542 stars 162 forks source link

Must declare the scalar variable "@initialVersion". #63

Closed yreynhout closed 13 years ago

yreynhout commented 13 years ago

I was trying to execute a command to create a new AR.

From peeking at the log of MsSqlServerEventStore I think it was probably broken by a merge/refactor between pwistrand's fix for deadlocks - which introduces this new variable - and aweiker's refactoring/cleanup: https://github.com/ncqrs/ncqrs/commit/699b6658555f4ee1523526b1abbd0a1372af8534#Framework/src/Ncqrs/Eventing/Storage/SQL/MsSqlServerEventStore.cs https://github.com/ncqrs/ncqrs/commit/9fdb026114672a344727334d94a72fece5249a58#Framework/src/Ncqrs/Eventing/Storage/SQL/MsSqlServerEventStore.cs

StackTrace: at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning() at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe) at System.Data.SqlClient.SqlCommand.ExecuteNonQuery() at Ncqrs.Eventing.Storage.SQL.MsSqlServerEventStore.UpdateEventSourceVersion(Guid eventSourceId, Int64 newVersion, SqlTransaction transaction) in d:\workspace\git\ncqrs\Framework\src\Ncqrs\Eventing\Storage\SQL\MsSqlServerEventStore.cs:line 425 at Ncqrs.Eventing.Storage.SQL.MsSqlServerEventStore.StoreEventsFromSource(Guid eventSourceId, Int64 eventSourceVersion, IEnumerable1 events, SqlTransaction transaction) in d:\workspace\git\ncqrs\Framework\src\Ncqrs\Eventing\Storage\SQL\MsSqlServerEventStore.cs:line 530 at Ncqrs.Eventing.Storage.SQL.MsSqlServerEventStore.Store(UncommittedEventStream eventStream) in d:\workspace\git\ncqrs\Framework\src\Ncqrs\Eventing\Storage\SQL\MsSqlServerEventStore.cs:line 340 at Ncqrs.Domain.UnitOfWork.Accept() in d:\workspace\git\ncqrs\Framework\src\Ncqrs\Domain\UnitOfWork.cs:line 91 at Ncqrs.Commanding.CommandExecution.Mapping.UoWMappedCommandExecutor.UoWMappedCommandExecutorCallbacks.ExecuteActionCreatingNewInstance(Func2 action) in d:\workspace\git\ncqrs\Framework\src\Ncqrs\Commanding\CommandExecution\Mapping\UoWMappedCommandExecutor.cs:line 49 at Ncqrs.Commanding.CommandExecution.Mapping.Attributes.MapsToAggregateRootConstructorAttributeHandler.<>cDisplayClass3.b2() in d:\workspace\git\ncqrs\Framework\src\Ncqrs\Commanding\CommandExecution\Mapping\Attributes\MapsToAggregateRootConstructorAttributeHandler.cs:line 22 at Ncqrs.Commanding.CommandExecution.Mapping.Attributes.MapsToAggregateRootConstructorAttributeHandler.Map(MapsToAggregateRootConstructorAttribute attribute, ICommand command, IMappedCommandExecutor executor) in d:\workspace\git\ncqrs\Framework\src\Ncqrs\Commanding\CommandExecution\Mapping\Attributes\MapsToAggregateRootConstructorAttributeHandler.cs:line 31 at CallSite.Target(Closure , CallSite , Object , Object , ICommand , IMappedCommandExecutor ) at System.Dynamic.UpdateDelegates.UpdateAndExecuteVoid4[T0,T1,T2,T3](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3) at Ncqrs.Commanding.CommandExecution.Mapping.Attributes.AttributeBasedCommandMapper.Map(ICommand command, IMappedCommandExecutor executor) in d:\workspace\git\ncqrs\Framework\src\Ncqrs\Commanding\CommandExecution\Mapping\Attributes\AttributeBasedCommandMapper.cs:line 59 at Ncqrs.Commanding.CommandExecution.Mapping.UoWMappedCommandExecutor.ExecuteInContext(IUnitOfWorkContext context, ICommand command) in d:\workspace\git\ncqrs\Framework\src\Ncqrs\Commanding\CommandExecution\Mapping\UoWMappedCommandExecutor.cs:line 17 at Ncqrs.Commanding.CommandExecution.CommandExecutorBase1.Execute(TCommand command) in d:\workspace\git\ncqrs\Framework\src\Ncqrs\Commanding\CommandExecution\CommandExecutorBase.cs:line 53 at Ncqrs.Commanding.ServiceModel.CommandService.<>c__DisplayClass91.b__8(ICommand cmd) in d:\workspace\git\ncqrs\Framework\src\Ncqrs\Commanding\ServiceModel\CommandService.cs:line 74 at Ncqrs.Commanding.ServiceModel.CommandService.Execute(ICommand command) in d:\workspace\git\ncqrs\Framework\src\Ncqrs\Commanding\ServiceModel\CommandService.cs:line 56 at radiochart_driver.Program.Main() in D:\workspace\hg\radiochart\radiochart-driver\Program.cs:line 21 at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args) at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() at System.Threading.ThreadHelper.ThreadStart_Context(Object state) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart()

marcofranssen commented 13 years ago

I think I fixed it. However my application still works, so hope it's the correct solution. Already did a pull request.

aproteau commented 13 years ago

I'm having the same issue.

marcofranssen commented 13 years ago

I don't know if you can see my pull request with the solution. You can fix it on your own repo until it is merged on the development branche.

aproteau commented 13 years ago

Thanks! I was able to fix the problem.

I've updated this method to include initialVersion :

private static void UpdateEventSourceVersion(Guid eventSourceId, long newVersion, long initialVersion , SqlTransaction transaction) { using (var command = new SqlCommand(Queries.UpdateEventSourceVersionQuery, transaction.Connection)) { command.Transaction = transaction; command.Parameters.AddWithValue("Id", eventSourceId); command.Parameters.AddWithValue("NewVersion", newVersion); command.Parameters.AddWithValue("initialVersion", initialVersion);

            command.ExecuteNonQuery();
        }
    }