sql - Transaction With db context in C# -
i trying commit transaction c# context:
private testdbentities context =new testdbentities(connectionstring); this.context.connection.open(); system.data.common.dbtransaction transaction = this.context.connection.begintransaction(); dbcommand command = this.context.connection.createcommand(); command.commandtext = "some insert/update query"; command.executenonquery(); transaction.commit();
but error message:
"the query syntax not valid. near identifier table_name, line 1, column 8."
query seems fine when directly execute directly on sql management studio. there solution?
sqlconnection conn = new sqlconnection(); sqlcommand command1 = new sqlcommand(); sqlcommand command2 = new sqlcommand(); sqltransaction trans = conn.begintransaction(); command1.transaction = trans; command2.transaction = trans; try { command1.executenonquery(); command2.executenonquery(); trans.commit(); } catch (sqlexception ex) { trans.rollback(); } { }
Comments
Post a Comment