Reputation: 609
i have a remote SQLSERVER instance wich i want to connect from my rails app hosted on heroku. My gemfile:
gem 'activerecord-sqlserver-adapter', '~> 3.2.12'
gem 'tiny_tds'
database.yml
production:
adapter: sqlserver
mode: dblib
dataserver: host.database.windows.net
database: items
username: username@host
password: password
azure: true
production.rb
dbconfig = YAML.load(ERB.new(File.read(File.join("config","database.yml"))).result)
ActiveRecord::Base.establish_connection dbconfig['production']
But i get the follwing error during the deploy process:
Writing config/database.yml to read from DATABASE_URL
Preparing app for Rails asset pipeline
Running: rake assets:precompile
rake aborted!
LoadError: Please install the sqlite3 adapter: `gem install activerecord-sqlite3-adapter` (sqlite3 is not part of the bundle. Add it to Gemfile.)
It seems that Active record require sqlite3 but if i have tiny_tds it should use sql server.
In development env all works fine. Sure there is something i am missing.
UPDATE
I've already set up the custom buildpack BUILDPACK_URL: https://github.com/firmhouse/heroku-buildpack-ruby-freetds.git and the DATABASE_URL config var.
UPDATE 2
Making a pp of dbconfig var while deploing display this
{"production"=>
{"adapter"=>"sqlite3",
"database"=>"dbname",
"username"=>"user",
"password"=>"pass",
"host"=>"127.0.0.1"}}
It seems that heroku overwrite my database.yml file, any suggestions?
UPDATE 3
I have set DATABASE_URL=sqlserver//user:pass@host:1433/database is this wrong?
Upvotes: 0
Views: 2411
Reputation: 151
I've faced same issue and finally found the answer.
You have to put the suffix below:
?encoding=uft-8&azure=true
So, your database_url will be like this:
sqlserver://[user]:[password]@[server.database.windows.net]:1433/[database]?encoding=uft-8&azure=true
Hope it helps
Upvotes: 2
Reputation: 18090
Looks like you need to use a custom buildpack.
Using this FreeTDS buildpack on Heroku
To use this buildpack you can pass in an option when creating your Heroku app:
heroku create my_new_sqlserver_app --buildpack https://github.com/firmhouse/heroku-buildpack-ruby-freetds.git
Or for current apps:
heroku config:add BUILDPACK_URL=https://github.com/firmhouse/heroku-buildpack-ruby-freetds.git
Configuring your database connection
After creating your app or setting up your existing app to use the buildpack, you need to modify the
DATABASE_URL
config variable to point to your sqlserver instance. We currently use a SQL Server 2008 Express edition:heroku config:add DATABASE_URL=sqlserver://username:password@sqlserver_host:1433/database_name
Upvotes: 0