I was working with just one database initially but I needed to add the clients other database which is a SQL Server database. I was able to connect but I am running into a few problems.
Original full database.yml
development:
adapter: postgresql
database: martin_development
username: *******
password: *******
pool: 5
timeout: 5000
development_sec:
adapter: sqlserver
host: *******
port: 1433
database: Database1
username: *******
password: *******
I get the following error:
TinyTds::Error (Database 'DATABASE1' does not exist. Make sure that the name is entered correctly.)
If I take out the database name so it looks like this:
development_sec:
adapter: sqlserver
host: *******
port: 1433
database:
username: *******
password: *******
Everything appears to run normal and I do not get any error messages in regards to a database not being found. However, that database does exist on the clients side.
I am confused on how to extract data from my customers SQL Server database. I am trying to follow along with some resources I found so my project files so far are looking like this:
Model (Mssql.rb)
class MssqlBase < ActiveRecord::Base
establish_connection :development_sec
self.abstract_class = true
end
Model(site.rb)
class Site < MssqlBase
end
Controller(sites_controller.rb)
class SitesController < ApplicationController
def index
@sites = Site.all
@hash = Gmaps4rails.build_markers(@sites) do |site, marker|
marker.lat site.latitude
marker.lng site.longitude
end
end
end
database.yml
development:
adapter: postgresql
database: martin_development
username: *******
password: *******
pool: 5
timeout: 5000
development_sec:
adapter: sqlserver
host: *******
port: 1433
database:
username: *******
password: *******
My goal is to start pulling data from the database but as of right now with this look in regards to my file I am getting the following error:
ActiveRecord::StatementInvalid (TinyTds::Error: Invalid object name 'sites'.: SELECT [sites].* FROM [sites]):
So just to recap I need it to read from the 'DATABASE1' but it is saying it does not exist. When I leave it out for some reason it is connecting with the server but I do not know which database. Now I am trying to pull the data but am getting invalid statements. Any help would be appreciated.
require 'rubygems';
require 'tiny_tds';
client = TinyTds::Client.new :username => '*******', :password => '*****', :host => 'host_url';
Obviously replace username, password, and host-url with your info. – Beartech