Connecting to SQLServer

New to rails. Installed rails on my XP desktop, and setup my first app
that will use an existing SQLServer database. I am able to connect to
SQLServer using odbc with following code.

require 'rubygems'
require 'ActiveRecord'

ActiveRecord::Base.establish_connection(
  :adapter => 'sqlserver',
  :mode => 'odbc',
  :dsn => 'Driver={SQL Server};Server=<server>;Database=<db>',
  :username => 'uid',
  :password => 'pwd'
)

class src <ActiveRecord::Base
  set_table_name 'Source'
  set_primary_key 'IDSource'
end

s = []
s = Source.find(1)
puts s.SourceName

I was able to connect and the code behaves as expected. However when I
try to use database.yml to specify the same connection information, I am
unable to connect using script/dbconsole.

#database.yml
development:
  adapter : sqlserver
  mode : odbc
  dsn : Driver={SQL Server};Server=<server>;Database=<db>
  username : <uid>
  password : <pwd>

When I start script/dbconsole, the error is
D:\work\rails\job>ruby script/dbconsole
Unknown command-line client for <db>. Submit a Rails patch to add
support!

My assumption is that my database.yml does not describe the connection
properly, since I am able to connect directly using establish_connection
method. Is there any documentation on how to specify a odbc connection
in yml for rails?

Here is the list of installed gems ::
D:\work\rails\job>gem list

*** LOCAL GEMS ***

actionmailer (2.3.2, 2.0.0)
actionpack (2.3.2, 2.0.0)
activerecord (2.3.2, 2.0.0)
activerecord-sqlserver-adapter (2.2.18)
activeresource (2.3.2)
activesupport (2.3.2, 2.0.0)
dbd-odbc (0.2.4)
dbi (0.4.1)
deprecated (2.0.1)
fxri (0.3.7, 0.3.6)
fxruby (1.6.19, 1.6.12)
hpricot (0.8.1, 0.6)
log4r (1.0.5)
ptools (1.1.6)
rails (2.3.2)
rake (0.8.7, 0.7.3)
sources (0.0.1)
test-unit (2.0.2)
win32-api (1.4.2, 1.0.4)
win32-clipboard (0.5.1, 0.4.3)
win32-dir (0.3.4, 0.3.2)
win32-eventlog (0.5.0, 0.4.6)
win32-file (0.6.1, 0.5.4)
win32-file-stat (1.3.3, 1.2.7)
win32-process (0.6.0, 0.5.3)
win32-sapi (0.1.4)
win32-sound (0.4.1)
windows-api (0.3.0, 0.2.0)
windows-pr (1.0.5, 0.7.2)

Thanks and appreciate any help leading to the resolution.

New to rails. Installed rails on my XP desktop, and setup my first app
that will use an existing SQLServer database. I am able to connect to
SQLServer using odbc with following code.

require 'rubygems'
require 'ActiveRecord'

ActiveRecord::Base.establish_connection(
:adapter => 'sqlserver',
:mode => 'odbc',
:dsn => 'Driver={SQL Server};Server=<server>;Database=<db>',
:username => 'uid',
:password => 'pwd'
)

class src <ActiveRecord::Base
set_table_name 'Source'
set_primary_key 'IDSource'
end

s = []
s = Source.find(1)
puts s.SourceName

I was able to connect and the code behaves as expected. However when I
try to use database.yml to specify the same connection information, I am
unable to connect using script/dbconsole.

script/dbconsole is just a handy shortcut for opening a connection to
the database using whatever command line tool that database provides
(eg with mysql it just runs the mysql utility). What rails is telling
you here is that it doesn't know what it should launch for this kind
of database (which isn't entirely surprising what with the sqlserver
being unbundled from rails). This isn't actually related to the
ability to connect to the database from a rails app though.

Fred

Email Address:richardlenawasae@gmail.com

Hi Guys,

I'm still new on Ruby on Rails and am now developing a real world
project, i have an existing sql server database, but am getting problem
when i try to migrate schema.rb without scaffolding since my tables has
big dozen of columns....

Please help..

Don't do that :wink: Migrations are an optional feature, designed to manage evolution of schemas created and maintained by Rails. It's perfectly possible to create and maintain your schema as you always have, and use Rails to access it.

So can i start scaffolding manually from ruby command prompt, but i know
scaffolding manually is quite tiresome and if i can really get another
alternative then fine...?

Do you really need scaffolding at all?

​Why not use the ActiveRecord Sql Server driver and rails console?​

As discussed last week, generally Rails scaffolding is not commonly used.

Database migrations are commonly used, but it is unclear to me what you are trying to do.

Are you attaching a Rails app to an existing database? (Like a database schema that is already built and works off some other application?) Migrations are designed to build out your database schema bit-by-bit (migration-by-migration), so you’ll have to get creative with how to work around that.

If you’re simply having problems running a migration (rake db:migrate), paste the full text of the error message you are seeing.

Hi,

Please help here....When i try to migrate database "{name}" it shows an
error says!

ActiveRecord::DuplicateMigrationNameError:.......

("Multiple migrations have the name #{name}") and i'm sure i was done
with this table #{name}") previously..

surely it cannot migrate.

DuplicateMigrationNameError Basically means that there is a class already defined with the same name

db/migrate/sometimestamp_your_migration_name.rb

class YourMigrationName < ActiveRecord::Migration

end

So give the migration file a different name and change the class name as well along with it. something like

db/migrate/sometimestamp_your_migration_name2.rb

class YourMigrationName2 < ActiveRecord::Migration

end

Thank You Vivek Sampara, but actually i have found i didn't save the
previous migration and it duplicate itself..