I programmed an application using rails and I can deploy it on a single machine. It uses a sqlite3 database that is created in the local machine.
Now I need to put that db on another machine, but I have no idea how. I installed a rails environment on the other machine and sqlite3. I configured the database.yml file this way:
development:
adapter: sqlite3
database: db/development.sqlite3
host: 172.**.**.**
pool: 5
timeout: 10000
username: username
password: password
However nothing happens. Do I need to configure something on the other machine? Am I missing something? Sorry if I seem ignorant, is the first time I do something like this.
Out of the box, no, you cannot, and it's actually discouraged in SQLite own manual:
If you have many client programs accessing a common database over a
network, you should consider using a client/server database engine
instead of SQLite.
You can take a look at various solutions built around SQLite to solve this problem here.
However, a much better solution would be to switch to another RDBMS such as MySQL or Postgresql. It should not impact your app much (as ActiveRecord does a nice job of isolating you of the DB specific instruction).
Related
I have been searching for a solution couple of days and done with nothing.
Is it really impossible to run rails app from a remote database?
My case:
I have a database located on one of my offices as a local server.
I need my rails app(hosted on some hosting service) to connect and run from this private database on this private server.
Is there really a solution or workaround?
And not related to rails but is it possible with django framework. just out of curiosity.
Thank you all very much for the answers!
You can set host in your databasey.yml like:
production:
adapter: postgresql
encoding: utf8
database: prod_db
username: prod_user
password: prod_pwd
host: 10.10.10.10
port: 5432
pool: 3
But you should have static ip or you can create VPN between two servers
I use 3 thin servers (behind an Nginx proxy) for my productive Rails app. Each of the thin servers produces 5 connections to the database. So my app has 15 connections in total. My Oracle admin complains that I use too many connections.
I do not know how to reduce the number of connections. I tried pool: 2 in database.yml, and restarted all thin servers, but my app still produces 15 connections. It seems that the pool setting is not used at all.
Of course, I could reduce the number of thin server, but I would like to know how to use pool.
I have another Rails app using PostgreSQL. Here, this parameter works as expected.
I use Rails 4.1 and Ruby 2.1
production:
adapter: oracle_enhanced
database: "(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=xxx)(PORT=12345)))(CONNECT_DATA=(SID=yyy)))"
pool: 2
username: ORACLE_USER
password: ORACLE_PASSWORD
I'd suggest you to open issue at https://github.com/rsim/oracle-enhanced - the maintainers check that more often.
After a reboot of the database server, everything works as expected ...
Not sure if these two can be compared, to bear with me. But what is the advantage (in a JRuby application) to run a configuration that's similar to:
production:
adapter: jdbc
encoding: utf8
jndi: java:comp/env/app
pool: 200
versus:
production:
adapter: jdbcmysql
encoding: utf8
database: tgc
#socket: /var/lib/mysql/mysql.sock
host: localhost
port: 3306
username: mysql
password: notarealpassword
Is one more flexible than the other? Can I better tune with JNDI? The reason I ask is because my Resque workers cannot access the DB when I use the JNDI version above. I have to use the latter configuration for things to work properly.
JNDI abstracts DB configuration into the app server. Benefits include being able to deploy the same app across servers utilizing different DBs and/or DB characteristics without changing the application itself.
It's often more a matter of policy/administration than anything else--keeping DB stuff isolated in this way gives more flexibility on the administrative side of things; things can be re-jiggered without the app (necessarily) being aware. (It doesn't always work like that in real life, naturally.) If the people managing the DBs/servers aren't the same people writing/deploying the app, JNDI can be very helpful.
That abstraction is manageable in other ways--Rails uses the DB config file, Spring might use server-specific config files, system properties, whatever. The differences are less technical, more managerial.
I am using postgresql database for my Heroku Application.
I have very large database on AmazonAws as heroku not providing the Postgresql Database.
Now my client want to switch to EngineYard from Heroku.
Can i use same database (w/o taking backup and then reload) for my application on the EngineYard?
If YES
How can i use or steps for using the Existing AmazonAws Database with the new EngineYard Application.
You can, but only if you are using a dedicated database. From the Heroku database FAQ
Shared Database
No, connecting to your database from machines outside of Heroku is not
supported. We recommend that you encapsulate data access in an API to
manipulate it.
Dedicated Database
It's possible to connect to our dedicated databases using our
pg:ingress feature. Please see using the PG console for more
information.
The database connection string is available in the DATABASE_URL config. You can run
$ heroku config --long
to view it. However, it won't probably work if you use a shared database because it seems connection is restricted to the Heroku net.
Surely this is just a case of getting the correct connection credentials for the DB regardless of where it's hosted?
For instance, if the DB is on Heroku, then ENV['DATABASE_URL'] give you everything you need. All these details then go in your database.yml as normal (assuming you're using ActiveRecord)
For the record, Heroku do provide Postgres and it's part of their core business.
I (sadly) have to deploy a rails application on Windows XP which has to connect to Microsoft SQL Server 2005.
Surfing in the web there are a lot of hits for connect from Linux to SQL Server, but cannot find out how to do it from Windows.
Basically I followed these steps:
Install dbi gem
Install activerecord-sql-server-adapter gem
My database.yml now looks like this:
development:
adapter: sqlserver
mode: odbc
dsn: test_dj
host: HOSTNAME\SQLEXPRESS
database: test_dj
username: guest
password: guest
But I'm unable to connect it. When I run rake db:migrate I get
IM002 (0) [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
I'm not a Windows user, so cannot understand really well the meaning of dsn element or so.
Does someone have an idea how to solve this?
Thanks in advance
With Alexander tips now I've modified my database.yml to:
development:
adapter: sqlserver
mode: odbc
dsn: Provider=SQLOLEDB;Data Source=SCADA\SQLEXPRESS;UID=guest;PWD=guest;Initial Catalog=test_dj;Application Name=test
But now rake db:migrate returns me:
S1090 (0) [Microsoft][ODBC Driver Manager] Invalid string or buffer length
Am I missing something?
this is a sample DSN, that connects to the database using the Windows user account (best when corporate network with domain login)
Provider=SQLOLEDB;Data Source=MyServer\MyInstance;Integrated Security=SSPI;Initial Catalog=MyDatabase;Application Name=My Application Name that will show up in the trace
So this uses the OLEDB provider for SQL Server. SQLNCLI can also be used, haven't tried it with ODBC. Actually this DSN isn't quite tested (have to wait for my admin to give me the necessary rights), but it was copied from a working script, that used SQLNCLI as the provider. The Data source is the server, and if it has a named instance, it has to be specified, so it's either just Server or Server\Instance. The Integrated Security=SSPI tells it you want to use Windows Authentication. Otherwise you specify the user and password to use using UID=MyUser;PWD=MyPassword. UID, User, Username, Password - I think all of these parameters work.
There is a great site over the internet that provides all kinds of DSN samples, just can't find it anywhere. If I find it, I will let you know.
If you haven't got any provider in Rails, check out if Rails supports Windows Component Object Model (COM). And if it does, you can even initialize the ADODB.Connection COM class, work with ADO thereon.
Ah, here is that site I was talking about: http://www.connectionstrings.com/