Unit Testing the Use of TransactionScope

I’m just now sitting with the same problem and to me there seems to be two solutions: Don’t solve the problem. Create abstractions for the existing classes that follows the same pattern but are mockable/stubable. Edit: I’ve created a CodePlex-project for this now: http://legendtransactions.codeplex.com/ I’m leaning towards creating a set of interfaces for working with … Read more

Transactional annotation on whole class + excluding a single method

There are different transaction propagation strategies to use. These exist in the enum Propagation. The ones you might want to use are /** * Execute non-transactionally, suspend the current transaction if one exists. * Analogous to EJB transaction attribute of the same name. * <p>Note: Actual transaction suspension will not work on out-of-the-box * on … Read more

How to fix mandrill / mailchimp transactional email issue recipient-domain-mismatch

There is two possible cause for this issue: – 1. You’re on a Trial plan (aka DEMO MODE) While in demo mode, you can only send to verified sending domains that you’ve added to the account. This restriction is lifted when blocks are purchased and the account is fully activated. – 2. Your DNS settings … Read more

How to test that a certain function uses a transaction in Rails and rspec 2

You should look at the problem from a different perspective. Testing whether a function uses a transaction is useless from a behavioral viewpoint. It does not give you any information on whether the function BEHAVES as expected. What you should test is the behavior, i.e. expected outcome is correct. For clarity, lets say you execute … Read more

now() default values are all showing same timestamp

That is expected and documented behaviour: From the manual: Since these functions return the start time of the current transaction, their values do not change during the transaction. This is considered a feature: the intent is to allow a single transaction to have a consistent notion of the “current” time, so that multiple modifications within … Read more

Cannot access SqlTransaction object to rollback in catch block

using (var Conn = new SqlConnection(_ConnectionString)) { SqlTransaction trans = null; try { Conn.Open(); trans = Conn.BeginTransaction(); using (SqlCommand Com = new SqlCommand(ComText, Conn, trans)) { /* DB work */ } trans.Commit(); } catch (Exception Ex) { if (trans != null) trans.Rollback(); return -1; } } or you could go even cleaner and easier and … Read more

Is Explicit Transaction Rollback Necessary?

No, its not specifically needed, however I can think of 2 reasons why it might be a good idea: Clarity Some might argue that using transaction.Rollback() makes it clearer under what circumstances the transaction will not be committed. Releasing locks When dealing with transactions it is important to realise the certain locks will only be … Read more

When does “SqlConnection does not support parallel transactions” happen?

You’ll get this if the connection already has an uncommitted transaction and you call BeginTransaction again. In this example: class Program { static void Main(string[] args) { using (SqlConnection conn = new SqlConnection(“Server=.;Database=TestDb;Trusted_Connection=True;”)) { conn.Open(); using (var tran = conn.BeginTransaction()) { using (var cmd = new SqlCommand(“INSERT INTO TESTTABLE (test) values (‘” + DateTime.Now.ToString() + … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)