# ActiveRecord::Rollback Config Help

**URL:** <https://www.ruby-forum.com/t/activerecord-rollback-config-help/182468>\
**Category:** Ruby\
**Created:** [January 28, 2010, 4:56pm UTC](https://www.ruby-forum.com/t/activerecord-rollback-config-help/182468 "2010-01-28T16:56:18Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![kels0n](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/ed655f/32.png) [@kels0n](https://www.ruby-forum.com/u/kels0n)\
**Post date:** [January 28, 2010, 4:56pm UTC](https://www.ruby-forum.com/t/activerecord-rollback-config-help/182468/1 "2010-01-28T16:56:18Z")

</div>

I’m struggling with why ActiveRecord isn’t rolling back my  
transactions. I’ve ran the same code at my home machine and it works  
but on my work machine it doesn’t and I’m hoping will see the  
glaringly obvious configuration problem that can’t see. I can connect  
to the database and perform actions just fine.

I’m running Ruby on Windows XP and connecting to SQL Server 2005.

> ruby --version  
> ruby 1.8.6 (2008-08-11 patchlevel 287) [i386-mswin32]

> gem list --local

\*\*\* LOCAL GEMS \*\*\*

actionmailer (2.3.5, 1.3.6)  
actionpack (2.3.5, 1.13.6)  
actionwebservice (1.2.6)  
activerecord (2.3.5, 1.15.6)  
activerecord-sqlserver-adapter (2.3)  
activeresource (2.3.5)  
activesupport (2.3.5, 1.4.4)  
autotest (4.2.3)  
dbd-odbc (0.2.4)  
dbi (0.4.1)  
deprecated (2.0.1)  
echoe (4.1)  
ezcrypto (0.7.2)  
fxri (0.3.7, 0.3.6)  
fxruby (1.6.16)  
gemcutter (0.3.0)  
hpricot (0.6.164)  
json\_pure (1.2.0)  
log4r (1.0.5)  
mocha (0.9.8)  
ptools (1.1.6)  
rack (1.0.1)  
rails (2.3.5, 1.2.6)  
rake (0.8.7, 0.8.1)  
ruby-opengl (0.60.0)  
rubyforge (2.0.3)  
rubygems-update (1.3.5)  
rubyzip (0.9.1)  
test-unit (2.0.1)  
thoughtbot-shoulda (2.10.2)  
win32-api (1.2.1, 1.2.0)  
win32-clipboard (0.4.4)  
win32-dir (0.3.2)  
win32-eventlog (0.5.0)  
win32-file (0.5.5)  
win32-file-stat (1.3.1)  
win32-process (0.5.9)  
win32-sapi (0.1.4)  
win32-sound (0.4.1)  
windows-api (0.2.4)  
windows-pr (0.9.3)

The script I’m using to test transactions is:

require ‘active\_record’

class TestRollback \< ActiveRecord::Base  
end

ActiveRecord::Base.establish\_connection(  
:adapter =\> ‘sqlserver’,  
:username =\> ‘user’,  
:password =\> ‘pass’,  
:database =\> ‘testdb’,  
:host =\> ‘localhost’  
)

TestRollback.transaction do  
TestRollback.create(:name =\> ‘Test’)  
raise ActiveRecord::Rollback  
end

TestRollback.find(:all) # returns [#\<TestRollback name: “Test”\>]

The only difference between this configuration and my one at home is I  
don’t have version 1.15.6 of the activerecord gem installed on my home  
machine. However, this script needs to use that version of  
activerecord because of some legacy code that I inherited and haven’t  
had a chance to rewrite. I’m hoping there’s a way around this without  
having to rewrite the code.

Any ideas?

---

<div class="post-metadata">

**Author:** ![kels0n](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/ed655f/32.png) [@kels0n](https://www.ruby-forum.com/u/kels0n)\
**Post date:** [January 29, 2010, 9:24am UTC](https://www.ruby-forum.com/t/activerecord-rollback-config-help/182468/2 "2010-01-29T09:24:23Z")

</div>

2010/1/28 kels0n [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> activerecord because of some legacy code that I inherited and haven’t  
> had a chance to rewrite. I’m hoping there’s a way around this without  
> having to rewrite the code.
> 
> Any ideas?

I can’t help you with AR but just making sure we exclude the easy  
mistakes which still happen all the time: you have verified that the  
record in question is not in the table before the TX starts, did you?

Kind regards

robert
