3

I want to develop a RoR application using MS SQL Express but I cannot figure out how to connect to the database. I tried

development:
adapter: sqlserver
database: historicDB
username: dxt
password: dxt
host: DBI:ADO:Provider=SQLNCLI;Data Source=localhost\SQLEXPRESS;InitialCatalog=historicDB;User Id=dxt;Password=dxt;

and

development:
adapter: sqlserver
database: historicDB
host: localhost\SQLEXPRESSS
username: dxt
password: dxt

I also installed dbi,dbd-odbc,activerecord-sqlserver-adapter but nowthing works I always get

   ActiveRecord::ConnectionNotEstablished

on the welcome screen

Igor Kulman
  • 16,211
  • 10
  • 57
  • 118

4 Answers4

3

First, use the TinyTDS gem and consult this page on using a named instance. https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/wiki/Using-TinyTds

You should be able to do this:

development:
  adapter: sqlserver
  database: historicDB
  dataserver: localhost\SQLEXPRESSS
  username: dxt
  password: dxt
MetaSkills
  • 1,954
  • 18
  • 15
  • I didn't understand that from the Wiki. It made me think that if I needed to use a named instance, I had to specify that in a freetds.conf file. I was then struggling to find where to create it. This makes much more sense. So glad I found it. – Wayne Phipps Jul 18 '14 at 11:42
  • I had to put `localhost:1433\SQLEXPRESS` as `port:` attribute didn't work – Andre Figueiredo Feb 10 '17 at 22:51
1

In old docs you will find infos about using dbi and dbi-odbc, but these are outdated.

The current state of art is using the sqlserver-adapter with TinyTds:

You will find Infos how to setup here: https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/wiki

Klaus
  • 903
  • 8
  • 19
  • I managed to get through all the steps (devkit,odbc dsn ..) but in the end I still get ActiveRecord::ConnectionNotEstablished – Igor Kulman Mar 03 '11 at 17:14
0

I haven't used this in the exact same configuration that you showed above but this link may help: http://rob-rowe.blogspot.com/2010/10/getting-rails-3-up-on-windows.html

Rob
  • 166
  • 1
  • 4
  • How did you manage to install Development Kid ? I run ruby dk.rb init and it finds my install dir, then i run ruby dk.rb install and it looks it installed but when I try to install anything I get an error that required build tools are not installed – Igor Kulman Mar 03 '11 at 14:13
  • I followed these instructions: https://github.com/oneclick/rubyinstaller/wiki/Development-Kit specifically section 4. After I did that I was able to get it to work. – Rob Mar 03 '11 at 14:38
  • I did the same but section 5 failed – Igor Kulman Mar 03 '11 at 15:17
  • I manage to install DevKit succesfully with some effort but still ActiveRecord::ConnectionNotEstablished – Igor Kulman Mar 03 '11 at 17:19
  • What version of windows are you using? Is it 32-bit or 64-bit? – Rob Mar 03 '11 at 19:42
  • 32bit Windows XP exactly as the tutorial – Igor Kulman Mar 03 '11 at 20:10
  • what does the .NET connection string look like for that DB? – Rob Mar 03 '11 at 20:32
  • for .NET it is Data Source=localhost\SQLEXPRESS;uid=dxt;pwd=dxt;database=historicDB. I have created a System DN called historicDB in Control Panel in ODBC for this connection string and tried using it, but no success – Igor Kulman Mar 04 '11 at 08:54
  • I tried the connection in ruby and this code return the count of record, so the ODBC alias works require "odbc" DSN = "historicDB" USER = "dxt" PWD = "dxt" ODBC.connect(DSN, USER, PWD) do |dbh| dbh.run("SELECT COUNT(*) FROM UsersInTime") do |sth| print sth.fetch[0] end end – Igor Kulman Mar 04 '11 at 11:47
0

This worked for me, though I set the dynamic port manually and I know that it's not a good solution ( I found the dynamic port SQL Server Browser was using in my box ).

production:
  adapter: sqlserver
  host: 'WIN10'
  port: 53540
  database: redmine
  username: REDMINE1
  password: "redminepassword"
BHP
  • 443
  • 4
  • 13