Trubelshooting MS Sql database connection

267 views
Skip to first unread message

Fredrik TiC Jansson

unread,
Oct 26, 2010, 4:41:20 AM10/26/10
to Ruby on Rails: Talk
Hello i have been atempting to move a project from sqlite database to
a sql server database with absolutly no success. i am now going to
document my entire process so that mabey someone can se the error of
my ways. And if some one else has this problem this migth act as a
troubleshooting guide.

OS: windows server 2003 latest sp
Sql: Sql server 2008

1. Install ruby 192.p0 from http://rubyinstaller.com/downloads (ticked
both boxes ie add to PATH and associate files)
installation folder is c:/ruby192

2.Install rails via
"gem install rails"

3. Install mongrel via
"gem install mongrel --pre"

4. install the sql adapter via
"gem install activerecord-swlserver-adapter"

5. install dbd-odbc via
"gem install dbd-odbc"
this also installed the dbi gem so i wont install this from a separate
command

Ok now everything i need to start RoR with mongrel and Sql Server
should be installed as far as i know on to the gem file

gem 'rails'#, '3.0.1'

require 'activerecord-sqlserver-adapter'
gem 'mongrel', '1.2.0.pre2'
require 'dbi'

and then the database.yml

development:
adapter: sqlserver
mode: odbc
database: NameOfMyDB
host: localhost
dsn: name_of_my_db
autocommit: true
username: something
password: something

Notes about this conf
dsn is the same name as the dsn i created with the odbc data source
administrator tool this is a system DSN by the way i have also tried
with file DSN

Ok now on to running my app

i go to the directory wich is located as follows

D:/projects/railsdev/projectname/

so i go there and execute
bundle install the result of this is
Error require: no such file to load --activerecord-sqlserver-adapter

if i change my require to a gem command everything is installed and
the server starts when i try to connect to the database i get another
error LoadError (no such file to load --odbc)

i have been loosing sleep over this please tell me what am i doing
wrong ?


Rodolinux

unread,
Oct 26, 2010, 7:18:57 AM10/26/10
to rubyonra...@googlegroups.com


--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonra...@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-ta...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.


take a look at http://www.10pines.com/content/deploy-ruby-rails-windows-2008-server-and-iis-70

greets
--
http://www.rodolinux.com.ar

"I must not fear. Fear is the mind-killer. I will face my fear. I will permit it to pass over me and through me. And when it has gone past I will turn the inner eye to see its path. Where the fear has gone there will be nothing. Only I will remain." - Bene Geserit's Fear Lethany - Dune Trilogy - Frank Herbert

Fredrik TiC Jansson

unread,
Oct 26, 2010, 8:41:09 AM10/26/10
to Ruby on Rails: Talk
Thanks seems rather comprehensive i will go through your tutorial.
> > rubyonrails-ta...@googlegroups.com<rubyonrails-talk%2Bunsu...@googlegroups.com>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/rubyonrails-talk?hl=en.
>
> take a look athttp://www.10pines.com/content/deploy-ruby-rails-windows-2008-server-...
>
> greets
> --http://www.rodolinux.com.ar

Rodolinux

unread,
Oct 26, 2010, 9:18:42 AM10/26/10
to rubyonra...@googlegroups.com
It's not my tutorial. Just I found it some days ago

To unsubscribe from this group, send email to rubyonrails-ta...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.




--

Fredrik TiC Jansson

unread,
Oct 27, 2010, 4:02:39 AM10/27/10
to Ruby on Rails: Talk
I finally got it working after a lot of googeling around big thanks
to http://github.com/rails-sqlserver/activerecord-sqlserver-adapter/wiki/Platform-Installation---Windows
for pointing me towards ruby-odbc which was the final peice to solve
my puzzle

How to get Ruby on Rails working with MS SQLServer2008 and windows
server 2003
This mini tutorial assumes MS SQLServer2008 is installed and running i
will be using mongrel to deploy

1. Install ruby via www.rubyinstaller.org (i used 1.8.7 version)
2. Install the DevKit (otherwise all gems won´t install properly)
3. Start a command promt with ruby via the start menu
4. Install rails
gem install rails
5. Get a cup of coffee this will take a while
6. install mongrel
gem install mongrel --pre (2010-10-27 this was the way to do it, this
will change)
7. install ruby-odbc
gem install ruby-odbc
8. install activerecord-sqlserver-adapter
gem install activerecord-sqlserver-adapter
9. install dbi
gem install dbi
10. install rails-dbi
gem install rails-dbi
NOTE: the reason for installing rails dbi and putting gem 'rails-
dbi', :require => 'dbi' in the gem file
is a conflict with the dbi and the deprecated gems. This issue migth
be resolved in the future.
11. Now its time to get on with editing our gemfile

put this in it

gem 'rails-dbi', :require => 'dbi'
gem 'ruby-odbc'
gem 'activerecord-sqlserver-adapter'
gem 'mongrel', '1.2.0.pre2' #this line will probably change in the
future this is written 2010-10-27


Then you need a connection string this will be in your config/
database.yml file


development:
adapter: sqlserver
driver: Sql Client
mode: odbc
database: DatabaseName
host: localhost/SQLSERVER2008
dsn: dsn_name
autocommit: true
username: user
password: pass

NOTE:
# localhost migth suffice or if you have mutilple named instances like
me you have to include that as well
About dsn:
the dsn is created via the Data Sources(ODBC) tool under
administrative tools
Create a System DSN with the same name as dsn: dsn_name under client
configuration use TCP/IP(this should be default just adding this so
you know that this is correct)

now try to create a new project and a scaffold do a bundle install and
rake db:migrate if all went well you should be able to start your
server via rails server and start doing som CRUD against your
SQLServer2008 database
> > <rubyonrails-talk%2Bunsu...@googlegroups.com<rubyonrails-talk%252Buns...@googlegroups.com>

Fredrik TiC Jansson

unread,
Oct 27, 2010, 4:06:59 AM10/27/10
to Ruby on Rails: Talk
Reply all
Reply to author
Forward
0 new messages