0

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?

stuartc
  • 2,244
  • 2
  • 24
  • 31
  • 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](http://odbc-rails.rubyforge.org/), 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. A properly written ODBC client application uses ODBC primitives and escapes in queries -- and the *driver* tailors them to the target DBMS API. Rails should never care what DBMS you're hitting. – TallTed Jul 03 '14 at 20:23

2 Answers2

1

You should use TinyTDS with the adapter, not ODBC. I have TinyTDS support even in the latest 2.3 versions. Here is the wiki page.

https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/wiki/Using-TinyTds

The good thing about TinyTDS is that it is tested to return good data from every type on SQL Server and is unicode safe.

MetaSkills
  • 1,954
  • 18
  • 15
-1

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
  • 2,829
  • 3
  • 22
  • 19
  • 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 Jun 11 '10 at 08:59
  • 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 Jun 13 '10 at 14:55
  • TinyTDS is so much easier and the sql server adapter (not the odbc) one is so well tested and really leverages all that SQL Server needs. – MetaSkills Sep 13 '11 at 14:29