views:

174

answers:

2

I have been using MSSQL 2005 with Rails for quite a while now, and decided to bump my gems up on one of my projects and ran into a problem.

I moved from 2.2.22 to 2.3.8 (latest as of writing) and all of a sudden I got this:

ODBC::Error: S1090 (0) [unixODBC][Driver Manager]Invalid string or buffer length

I'm using a DSN connection with FreeTDS my database.yml looks like this:

adapter: sqlserver
mode: ODBC
dsn: 'DRIVER=FreeTDS;TDSVER=7.0;SERVER=10.0.0.5;DATABASE=db;Port=1433;UID=user;PWD=pwd;'

Now in the mean time I moved back to 2.2.22 and there are no deprecation warnings and everything seems fine but obviously for the sake of being up to date, any ideas what could have changed in the adaptor that could cause this?

A: 

I have to wonder why you're using activerecord-sqlserver-adapter when you're actually going through ODBC?

I would recommend checking out this page, which will walk you through getting things rolling with a proper ODBC setup -- which will, in turn, let you shift your Rails apps from SQL Server to any other ODBC-accessible target when/if that's desirable.

TallTed
Thank you, I'm checking it out. A question I just asked the other poster, is using that method, if your adaptor is set just to ODBC, where does Rails know where to tailor the queries for MSSQL?
stuartc
When ODBC client applications are written properly, their queries use ODBC primitives and escapes -- and the *driver* tailors them to the target DBMS API. Rails should never need to know or care whether you're hitting SQL Server, Oracle, Ingres, Informix, DB2, MySQL, PostgreSQL, theNextBigDBMS -- just ODBC. The driver should handle the rest.For instance, a TIMESTAMP whose syntax differs with the DBMS would be passed to the ODBC driver as "{ts 'YYYY-MM-DD HH:MM:SS.nnnnnn'}" (minus the double-quotes) -- and the driver would transform this as appropriate for the target DBMS.
TallTed
A: 

I just had a similar problem. Removing the activerecord-sqlserver-adapter and using the activerecord-odbc-adapter (version 2.0). Works for me.

I just uninstalled activerecord-sqlserver-adapter, dbi, and dbd-odbc. And then installed activerecord-odbc-adapter and changed my db config to be something like

your_database:
  adapter: odbc
  dsn: YourDNS
  username: YourUsername
  password: YourPassword

Works sweet : )

Andrew
That looks much nicer, but how does Rails know to use the sqlserver adaptor, or more specifically does ActiveRecord alter it's queries specially for MSSQL?
stuartc
I don't really understand it completely sorry. But I think that the activerecord-odbc-adapter talks to FreeTDS which intern talks to the sql server. Anyway my rails app is working fine without the activerecord-sqlserver-adapter. But I'm only calling stored procs on the sql servers, so maybe this wouldn't work for normal queries. Worth a try though. Good luck.
Andrew