Skip to content

connection.execute() always returns -1 on Rails 4.0.4, Ruby 2.1.1 #325

@paquettej

Description

@paquettej

I am trying to use execute() to run a query to compute percentages over a partition, so I would like to use connection#execute to run it. However, it returns -1 even though the sql works fine in SQL Server Management Studio.

To eliminate issues from my query, I tried a simple count(*) via the rails console and found that that also returns -1.

Note that I am successfully using sql server in this application without issue, so I am confident in the configuration and setup in general.

Using activerecord-sqlserver-adapter via:

ruby '2.1.1'
gem 'rails', '4.0.4'    
gem 'activerecord-sqlserver-adapter', git: 'git://github.com/rails-sqlserver/activerecord-sqlserver-adapter.git'
gem 'tiny_tds'

Given the following class:

class MetricsDatabase < ActiveRecord::Base
  establish_connection 'metricsdb'
end

With the following config:

metricsdb:
  adapter: sqlserver
  host: ******
  mode: dblib
  dataserver: ******\metricsdb
  database: wms
  username: *****
  password: ******

In the console:

2.1.1 :031 > MetricsDatabase.connected?
 => true 
2.1.1 :032 > MetricsDatabase.connection.execute("select count(*) from [metric];")
   (64.6ms)  select count(*) from [metric];
 => -1 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions