Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7606727
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T00:28:54+00:00 2026-05-31T00:28:54+00:00

Rails 3.1, Ruby 1.9.2, using a SQL Server 2008 database through the activerecord-sqlserver-adapter gem.

  • 0

Rails 3.1, Ruby 1.9.2, using a SQL Server 2008 database through the activerecord-sqlserver-adapter gem. I’m working with a legacy database, so this was not voluntary.

I’m running into an odd problem with ActiveAdmin. I’ve not used ActiveAdmin before, and added it after watching a Railscast. Followed the standard installation instructions, and I’m able to log into the admin console.

When I add a model:

rails generate active_admin:resource Payment

The model (in plural) is now visible on the ActiveAdmin dashboard. However, when I click on the link, I get the following error:

TinyTds::Error: No column name was specified for column 2 of '__rnt'.: EXEC 
sp_executesql N'SELECT TOP (1) [__rnt].* FROM ( SELECT ROW_NUMBER() OVER (ORDER
BY [Payments].[UPaymentID] ASC) AS [__rn], 1 FROM [Payments] ) AS [__rnt] 
WHERE [__rnt].[__rn] > (0) ORDER BY [__rnt].[__rn] ASC'

Now, this query returns the same error if I run it directly on the SQL Server database – it doesn’t like the unnamed column of “1”.

Started digging to see what the issue was. The obvious places to look would be in the transitions between activeadmin and activerecord, and then activerecord and the SQL Server adapter. Here’s the stack trace for the first intersection:

activerecord (3.1.0) lib/active_record/relation/finder_methods.rb:197:in `exists?'  
activeadmin (0.4.2) lib/active_admin/views/pages/index.rb:41:in `items_in_collection?'  
activeadmin (0.4.2) lib/active_admin/views/pages/index.rb:20:in `main_content'

It looks like items_in_collection? is calling exists? on a collection that has had order filters removed. At this point, we’re handing off to ActiveRecord. If we look at the transition from ActiveRecord to the SQL Server adapter, it looks as if the SELECT statement has already been formed:

activerecord-sqlserver-adapter (3.1.6) lib/active_record/connection_adapters/sqlserver/database_statements.rb:348:in `do_exec_query'
activerecord-sqlserver-adapter (3.1.6) lib/active_record/connection_adapters/sqlserver/database_statements.rb:24:in `exec_query'
activerecord-sqlserver-adapter (3.1.6) lib/active_record/connection_adapters/sqlserver/database_statements.rb:297:in `select'
activerecord (3.1.0) lib/active_record/connection_adapters/abstract/database_statements.rb:18:in `select_all'
activerecord (3.1.0) lib/active_record/connection_adapters/abstract/query_cache.rb:61:in `block in select_all'

I’m totally confused as to why the SQL would be generated the way that it is. There are a couple of candidate problem areas:

  1. I’m working on a legacy database with an odd schema. I’m having to set table names and primary key names within my models. I don’t think this is the issue, since the query that is coming out seems to use the appropriate primary key and table names.
  2. Problems with the activerecord-sqlserver-adapter gem. However, I pulled the source code, and it sure doesn’t look like there is anything there that would be assembling this query in that way.

Has anyone run into anything similar to this? It may be that I’ll just need to debug my way through the whole stack to see what’s going on. Figured it would be worth checking here first though.

Edit: I’m now fairly sure this is a bug in activerecord-sqlserver-adapter. Will post resolution here once I have it.

Edit2: Can reproduce the error without ActiveAdmin at all. This is related to the way that the sql server adapter deals with offset queries. Calling

MyModel.offset(1).exists?

produces the same error. I have an ugly patch to the adapter which passes all the unit tests, but I’m going to try to find a more elegant solution before making a pull request.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T00:28:55+00:00Added an answer on May 31, 2026 at 12:28 am

    I’m not sure this is exactly the answer, but I patched my local code and your query works for me now.

    First, the github issue:

    https://github.com/rails/rails/issues/1623

    and then the pull request for arkadiyk’s fix:

    https://github.com/arkadiyk/rails/commit/7e2ddddb303d17adc825ebb691097a93902fa539

    The basic problem is finder_methods.rb, which has the existing code around line 187 or 188:

    relation = relation.except(:select).select("1").limit(1)
    

    MSSQL barfs on the unnamed column this generates, so the following code fixes it:

    relation = relation.except(:select).select("1 as o").limit(1)
    

    Hope that helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to connect Rails to SQL Server. I installed the activerecord-sqlserver-adapter and ruby-odbc
I just started using the new project type SQL Server 2008 Database. I can
I've developed a web interface for a legacy (vendor) database using Ruby on Rails.
This works locally, but not on production server. Using ubuntu 10.04, rails 3.0.7, ruby
I'm on Windows XP... Ruby 1.9.2 Rails 3.0.9 MS SQL Server 2005 I'm using
I am using Ruby on Rails 3.0.7 Cucumber 1.0.1, and Oracle as the database.
Novice here! I'm currently creating an application using Ruby on Rails. This particular application
I am unable to access a database table in rails. I am using ruby
This ruby/rails construct always puzzles me: User.where(:name => Thiago).limit(3).using(:slave_one) This must execute from left-to-right,
using Ruby on Rails 2.3.2, since I already created Scaffold for Story, so instead

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.