Dapper.Contrib Insert Fails #8

Closed
kouphax opened this Issue Jun 18, 2011 · 3 comments

Comments

Projects
None yet
4 participants
@kouphax

kouphax commented Jun 18, 2011

I am trying to use the Insert method from Dapper.Contrib and it keeps throwing an error.

using (SqlConnection conn = new SqlConnection(Program.ConnectionString))
{
    Author a = new Author
    {
        Username = "james@dapper.net",
        FullName = "James Hughes",
        CreatedDate = DateTime.Now
    };

    conn.Open();
    conn.Insert(a);
}

This code results in the following error

System.InvalidOperationException was unhandled
  Message=ExecuteNonQuery requires the command to have a transaction when the connection assigned to the command is in a pending local transaction.  The Transaction property of the command has not been initialized.
  Source=System.Data
  StackTrace:
       at System.Data.SqlClient.SqlCommand.ValidateCommand(String method, Boolean async)
       at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe)
       at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
       at Dapper.SqlMapper.ExecuteCommand(IDbConnection cnn, IDbTransaction tranaction, String sql, Action`2 paramReader, Object obj, Nullable`1 commandTimeout, Nullable`1 commandType) in C:\Projects\microorm-comparison\CodeSlice.Data\CodeSlice.Data\Dapper\SqlMapper.cs:line 836
       at CallSite.Target(Closure , CallSite , Type , IDbConnection , IDbTransaction , String , Object , Object , Nullable`1 , Nullable`1 )
       at System.Dynamic.UpdateDelegates.UpdateAndExecute8[T0,T1,T2,T3,T4,T5,T6,T7,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7)
       at CallSite.Target(Closure , CallSite , Type , IDbConnection , IDbTransaction , String , Object , Object , Nullable`1 , Nullable`1 )
       at Dapper.SqlMapper.Execute(IDbConnection cnn, String sql, Object param, IDbTransaction transaction, Nullable`1 commandTimeout, Nullable`1 commandType) in C:\Projects\microorm-comparison\CodeSlice.Data\CodeSlice.Data\Dapper\SqlMapper.cs:line 176
       at Dapper.Contrib.Extensions.SqlMapperExtensions.Insert[T](IDbConnection connection, T entityToInsert) in C:\Projects\microorm-comparison\CodeSlice.Data\CodeSlice.Data\Dapper\Extensions\SqlMapperExtensions.cs:line 175
       at CodeSlice.Data.Profilers.ProfileInsert.<Run>b__2() in C:\Projects\microorm-comparison\CodeSlice.Data\CodeSlice.Data\Profilers\ProfileInsert.cs:line 51
       at CodeSlice.Data.Profilers.ActionProfiler.Profile(String description, Action actionToProfile) in C:\Projects\microorm-comparison\CodeSlice.Data\CodeSlice.Data\Profilers\ActionProfiler.cs:line 16
       at CodeSlice.Data.Profilers.ProfileInsert.Run() in C:\Projects\microorm-comparison\CodeSlice.Data\CodeSlice.Data\Profilers\ProfileInsert.cs:line 39
       at CodeSlice.Data.Profilers.ProfileInsert.Exec() in C:\Projects\microorm-comparison\CodeSlice.Data\CodeSlice.Data\Profilers\ProfileInsert.cs:line 18
       at CodeSlice.Data.Program.Main(String[] args) in C:\Projects\microorm-comparison\CodeSlice.Data\CodeSlice.Data\Program.cs:line 24
       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()
  InnerException: 
@kstenson

This comment has been minimized.

Show comment
Hide comment
@kstenson

kstenson Jun 24, 2011

Hi kouphax, I had the exact issue too, check out this pull request for the changes that I made to get it working: SamSaffron#10

Hi kouphax, I had the exact issue too, check out this pull request for the changes that I made to get it working: SamSaffron#10

@SamSaffron

This comment has been minimized.

Show comment
Hide comment
@SamSaffron

SamSaffron Jul 19, 2011

Contributor

Can you try latest?

Contributor

SamSaffron commented Jul 19, 2011

Can you try latest?

@johandanforth

This comment has been minimized.

Show comment
Hide comment
@johandanforth

johandanforth Apr 23, 2015

Contributor

Fixed in later versions of Dapper.Contrib.

Contributor

johandanforth commented Apr 23, 2015

Fixed in later versions of Dapper.Contrib.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment