[ruby-dbi-users] DBI jtds Mssql 6.5 connection problem

Gene Nardi gene.nardi at gmail.com
Thu Dec 13 18:54:15 UTC 2012


I'm fairly new to jdbc and ruby but I have done a lot of perl DBI.  My
question is, 'Since it appears that the connection is being called without
specifying the TDS protocol, Do I have something wrong in my set up that is
not using the correct libraries?


I have the following code to connect to a Mssql 6.5 server...

1   require 'java'
2   require 'rubygems'
3   require 'jtds-1.2.5'
4   require 'dbi'
5
6   begin
7     dbh = DBI.connect('dbi:Jdbc:jtds:sybase://rohtest:1433','user',
'pass',{ 'TDS' => '4.2','driver' => 'net.sourceforge.jtds.jdbc.Driver' } )
8
9     stmt = dbh.prepare('select businessname from payer')
10   stmt.execute
11   stmt.fetch do |row|
12     p row
13  end
14 end

*producing an error stack trace...*
/usr/local/rvm/gems/jruby-1.6.5/gems/deprecated-2.0.1/lib/deprecated.rb:199
warning: already initialized constant Deprecate
DBI::DatabaseError: java.sql.SQLException: No current row in the ResultSet.
  connect at
/usr/local/rvm/gems/jruby-1.6.5/gems/dbd-jdbc-0.1.4/lib/dbd/jdbc/driver.rb:66
  connect at
/usr/local/rvm/gems/jruby-1.6.5/gems/dbi-0.4.5/lib/dbi/handles/driver.rb:33
  connect at /usr/local/rvm/gems/jruby-1.6.5/gems/dbi-0.4.5/lib/dbi.rb:148
   (root) at ruby-jtds.rb:7

*looking at
/usr/local/rvm/gems/jruby-1.6.5/gems/dbd-jdbc-0.1.4/lib/dbd/jdbc/driver.rb
it appears that a call to connect is being made without all the parameters
(highlighted below)
*   def connect(dbname, user, auth, attr)
      driverClass = attr["driver"]
      raise InterfaceError.new('driver class name must be specified as
"driver" in connection attributes') unless driverClass

      load(driverClass)

      *connection = java.sql.DriverManager.getConnection("jdbc:"+dbname,
user, auth)
      dbh = Database.new(connection)*

      (attr.keys - @driverAttributes).each { |key| dbh[key] = attr[key] }

      return dbh
    rescue NativeException => error
      raise DBI::DatabaseError.new(error.message)
    end

  end #Driver
end

*Since this is a 6.5 sql server it only communicates with TDS 4.2 protocol
and the default protocol for jtds is 8.0 the server can't respond to the
connection request.*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/ruby-dbi-users/attachments/20121213/295310f5/attachment-0001.html>


More information about the ruby-dbi-users mailing list