Is anyone running Rails 2.x against a MS SQL Server DB?

I am unable to get ActiveRecord session support to work under 2.x
against a SQL Server database. I'm starting to wonder if anyone is
running 2.x against SQL Server?

Is anyone running under the following configuration:

Rails 2.x
SQL Server 2000 DB (using AR adapter in ODBC mode)
AR store for ActionController session store.

I'd like to chat with you if you are.


hey Wes,
I will be running against a sql server 2000 or 2005, but I am still in
development. So I will keep an eye out for any information that you
find out.



I develop against MS SQL Server 2000 db's all the time.

My company has a whole bunch of legacy db's that are SQL Server 2000
db's. So far, I have not had a problem with the SQL Server AR
adapter, with FreeTDS, in ODBC mode with Rails 2.x.

But, then again, we don't do database session store. We use the Rails
2.x default cookie based session store. So, you may have uncovered a
bug. However, that seems unlikely. The SQL Server AR adapter was
around before Rails 2.x. And, prior to Rails 2.x, I was using db
session store.

The problems I do run into are not really with AR or SQL Server. But,
rather, I have to deal with a lot of legacy/non-Rails-esque database
designs. Things like non-surrogate PK's, composite PK's, weird FK
relationships, using PK's that contain periods and "@'s" . . . just
about every weird thing you can think of . . . I've come across.

The good thing is that so far, I have been able find workarounds for
all these situations.

If you can be a little bit more specific with you problem, maybe post
some error messages or something, I would be happy to help you out.

I used (don't any more) MS Sql Server using session store.

Double check your table permissions on the SQL Server, maybe something
is funky here.

Try going into the console and "" set some param and save
it, see if it works.

Try using save! instead of save in the console test to raise an
exception on failed save.

What does your test.log say?

Give us more details :slight_smile:


Here is some script/console output. We see that the session is in fact
an ActiveRecord object, hooked up to the sessions table, but that saving
the session appears to do nothing. No data end up in the database, and
notice how session.new_record? is still true after the save.


C:\eclipse\workspace\eSimplyOnlineRails>ruby script/console
Loading development environment (Rails 2.0.2)

session =

=> #<CGI::Session::ActiveRecordStore::Session id: nil, session_id: nil,
data: ni
l, updated_at: nil>


=> true


=> "sessions"


=> true

session[:test_key] = 3

=> 3

=> []!

=> []


=> true


=> 3


What does your test / development log say about these actions?


and here are the entries in the development.log file (note that all of
this is output on the instantiation of the session, nothing gets written
to the log after that).

On windows I have sometimes had that the server won't write to the log
file if it gets too full sometimes and definately won't if you have
say another console or server open.

Close all your servers and consoles that could be writing to
development.log. Delete or move the development.log and try again and
see if there is any more output....


I'm running 2.x against 2005, and all seems to be working fine. I've
ended up modifying the connection adapter to suit my needs though.

I dont think you can set session in the console you'll need to do it
from a controller i.e.

class TestController < ApplicationController
  def index
    session[:test_key] = 3
    render :text => "setting test key to 3"

  def read
    render :text => session[:test_key]


This works as expected. Using the edge sql server adapter.

Luke Pearce wrote:

I'm running 2.x against 2005, and all seems to be working fine. I've
ended up modifying the connection adapter to suit my needs though.

Just to clarify that - In my project I'm using a modified sql server

I created a new test project, using rails 2.0.2 and the edge sql
server adapter. I added that controller to get/set the session and it
all worked properly.


I see the same results in a fresh project using 2.0.2 and the 1.0 SQL
server adapter.

Thanks for the test code.

I'll post the problem with my other app. when I figure it out.


My problem appears to be related to the use of the object_transactions
plugin (see:, which
in turn, relies on the transaction-simple gem.

Removing the object-transactions plugin allows my session to save

I haven't figured out the exact reason yet, but I will and will post
when I have it.

If anyone understands the guts of the object_transactions plugin and/or
the transaction-simple gem and would like to chime in, I'm all ears.

It's incredibly frustrating to have moved to the object_transactions
plugin as an an effectively mandated part of the upgrade to Rails 2.0,
and then have it totally not work with the ActiveRecord session store.

My faith in being able to upgrade a Rails app. and even hope for plugins
to continue to work is extremely shaken.


Just one more thing to add some evidence to my claim.

If you install the object_transactions plugin (and by association, the
transaction-simple plugin) into a new Rails app. like the one that
Luke mentioned above, you will see the same behavior - your AR session
store will not be saved to/from anymore.

I am going to start a new post about this potential bug.


I _think_ the final answer is here: