Forum: Ruby on Rails Rails Configuration Question

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Eden Brandeis (Guest)
on 2005-12-20 21:36
(Received via mailing list)
Hello Everyone,

I have been reading this mailing list for a while and am impressed with
the
generous help that many here are eager to provide.  Perhaps someone will
be
able to shed some light on a configuration issue I am having.  Thank you
in
advance for any assistance.

First, system setup details:
#System Setup#
* OS: Fedora Core 4 running in a VMWare box on Windows XP
* Database: MS SQL Server (newer/est version - can find out if
necessary)
running on a Windows server on our network
* Access to SQL Server: Using unixODBC and FreeTDS to connect to the SQL
Server, I just set this up, so the versions are the newest
* Rails Version: I keep updating every time DHH posts something on the
Rails
page, so I guess 1.0

#Error Message and Supporting Information#
When I access the action controller for a model I created I get the
following error
DBI::DatabaseError in Bug#index
S1000 (0) [unixODBC][FreeTDS][SQL Server]Unable to connect to data
source

I also used to get this error in my model unit test code if I didn't
include
a manual connection with Model.establish_connection(...), but it went
away
yesterday when I twiddled around with the database.yml file a bit.

#Database Configuration#
Here is a cleaned up snippet from database.yml:

production:
  adapter: sqlserver
  mode: odbc
  dsn: DSNNAME
  username: WINDOMAIN\user
  password: ********

test, development, and production have identical entries.  My database
models are wrappers for non-rails tables and include primary key
redefinition, table definition, and foreign key relationships.

#Unit Test Example#
This is code from a working unit test that accesses the database:
require File.dirname(__FILE__) + '/../test_helper'

class BugTest < Test::Unit::TestCase
  def setup
    @bug = Bug.find(1)
  end

  def test_read
    assert_equal 1, @bug.id
    puts "Category => " + @bug.category.sCategory
    puts "Project => " + @bug.project.sProject
    puts "Area => " + @bug.area.sArea
    puts "PersonOpenedBy => " + @bug.person_opened_by.sFullName
    puts "PersonAssignedTo => " + @bug.person_assigned_to.sFullName
  end
end

This works perfectly and I assume must be using my database.yml for
connection info.

#Action Controller Code#
class BugController < ApplicationController
  def index
    @bugs = Bug.find(1)
  end
end

#Summary#
I can access the database using a unit test but not through a web
browser
against my action controller.
Peter Fitzgibbons (Guest)
on 2005-12-20 21:45
(Received via mailing list)
On 12/20/05, Eden Brandeis <ebrandeis@gmail.com> wrote:
> * OS: Fedora Core 4 running in a VMWare box on Windows XP
> DBI::DatabaseError in Bug#index
> production:
> #Unit Test Example#
>     puts "Category => " + @bug.category.sCategory
> #Action Controller Code#
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
>
>
The ODBC drivers do not accept Windows Integrated-security logins via
Rails.  I think this is a limitation of the ruby drivers?.  You'll have
to
create a sql-only login to use with your rails app.

Also, if you can get integrated security to "work" you'll be convincing
the
sql server that your linux login's authentication satisfies a login in
the
Active Directory, then the username: and password: in your database.yml
will
be left blank, as integrated security takes its authentication from the
users environment.



--
Eden Brandeis (Guest)
on 2005-12-20 23:06
(Received via mailing list)
Hi Peter,

Thank you for the response.  If "Windows Integrated-security logins via
Rails" doesn''t work, then why does my unit test against my model work
and a
manual connection using Model.establish_connection(...) work?  These are
both using the rails framework.  I thought SQL server will accept DSN
logins
using windows DOMAIN\USER style authentication.  Since isql, tsql, and
ActiveRecord all work with this setup, perhaps it is related to the
routing
through the webserver to Rails?  Do you have any other information or
ideas
about this problem?

Just for reference, I used the following guide for my setup:
http://wiki.rubyonrails.com/rails/pages/HowtoConne...

Thank you,

Eden
Lou Vanek (Guest)
on 2005-12-21 00:37
(Received via mailing list)
If you want to look under the hood and try to suss out what params
are actually being sent to the ODBC driver, you could add one line
to one of the ActiveRecord gem files:

   In method "def self.sqlserver_connection" of file
"sqlserver_adapter.rb"
   right _before_ this line:
     conn      = DBI.connect(driver_url, username, password)
   add this line:
     STDERR.puts "### ODBC connection params: #{driver_url.inspect}$
u:#{username}$ p:#{password}$"

Then run your tests.
Compare the params you see on the console standard error stream when you
test with
the values you see when you run in development mode. Do they differ at
all?
If they are exactly the same then I'm at a loss.
Eden Brandeis (Guest)
on 2005-12-21 02:37
(Received via mailing list)
Hi Lou,

Great tip.  Your post got me halfway to the info I need.  When I run my
unit
test, the connection info is displayed along with the test results, but
I
cannot figure out how to find the stderr.puts results when I hit the
controller from a web browser.  I am using Apache 2.0 with no
modifications
on Fedora Core 4.  Is there a way to access $stderr from the rails
console
or should I be looking for a log file in an Apache folder?

I am still new to rails and linux and don't know how to debug
controllers
and views effectively yet.

Thanks,

Eden
Joe Van Dyk (Guest)
on 2005-12-21 05:05
(Received via mailing list)
On 12/20/05, Eden Brandeis <ebrandeis@gmail.com> wrote:
> Hi Lou,
>
>  Great tip.  Your post got me halfway to the info I need.  When I run my
> unit test, the connection info is displayed along with the test results, but
> I cannot figure out how to find the stderr.puts results when I hit the
> controller from a web browser.  I am using Apache 2.0 with no modifications
> on Fedora Core 4.  Is there a way to access $stderr from the rails console
> or should I be looking for a log file in an Apache folder?

Should be in the Rails log file somewhere (i.e. either development.log
or production.log).
Deej (Guest)
on 2005-12-21 09:13
Eden Brandeis wrote:
> Hello Everyone,
>
> I have been reading this mailing list for a while and am impressed with
> the
> generous help that many here are eager to provide.  Perhaps someone will
> be
> able to shed some light on a configuration issue I am having.  Thank you
> in
> advance for any assistance.
>
> First, system setup details:
> #System Setup#
> * OS: Fedora Core 4 running in a VMWare box on Windows XP
> * Database: MS SQL Server (newer/est version - can find out if
> necessary)
> running on a Windows server on our network
> * Access to SQL Server: Using unixODBC and FreeTDS to connect to the SQL
> Server, I just set this up, so the versions are the newest
> * Rails Version: I keep updating every time DHH posts something on the
> Rails
> page, so I guess 1.0
>
> #Error Message and Supporting Information#
> When I access the action controller for a model I created I get the
> following error
> DBI::DatabaseError in Bug#index
> S1000 (0) [unixODBC][FreeTDS][SQL Server]Unable to connect to data
> source
>
> I also used to get this error in my model unit test code if I didn't
> include
> a manual connection with Model.establish_connection(...), but it went
> away
> yesterday when I twiddled around with the database.yml file a bit.
.............


Hello - I myself am still learning but I noticed a post saying about
rubyforums.co.uk aparrently they have good info there - it just opened
too, this may be a good place to ask for advice, I hop you find yoor
answers
Thanks
Eden Brandeis (Guest)
on 2005-12-21 21:55
(Received via mailing list)
Lou,

Just to follow-up to your suggestion, I found that I could raise an
exception in sqlserver_adapter.rb instead of using stderr and this shows
up
in my web browser.  The connection string is identical, but my test code
(action controller functional test and model unit test) is able to
connect
(with the raise removed of course), but accessing via the web browser
doesn't work.

What is the difference between calling the ruby odbc through test code
and
through a web browser?  Why does it work for one and not the other?  Any
help is much appreciated.

Thank you,

Eden
Lou Vanek (Guest)
on 2005-12-21 21:55
(Received via mailing list)
I doubt this is a Ruby/Rails thang, but most likely file
permissions/account permissions.

Are you running the tests
under a different account than what apache is being run under? If so,
that suggests that the apache account has limited read/execute
permissions,
which is actually quite common.

Your apache httpd.conf file probably indicates the account user name:
'apache', 'www', or 'nobody'. Log on under this account and try to
connect
to any db via odbc. You'll probably fail, due to permissions is my
guess.
Try running the Rails tests now. It should probably fail under the
apache account.

A fix? You might try adding the apache user to the same group that your
test
account belongs to (/usr/bin/gpasswd -a <apache_username>
<group_name_that_test_account_belongs_to>).

Alternate fix: change the group that the odbc driver and database may be
used by (chown or chgrp).

Or simple change the apache user account to the same account that your
tester is running under. That could be dangerous, but you might try it
just to prove that this is a permissions issue.
Eden Brandeis (Guest)
on 2005-12-21 21:55
(Received via mailing list)
Lou,

I think you are correct as to the nature of the problem.  I am not ready
to
dig into the configuration yet, so I tried running WebBrick as my
development user and everything works great.  The apache user just needs
access to the proper odbc files.

Thank you everyone for your help,

Eden
This topic is locked and can not be replied to.