Oracle TNS error with Ruby on Rails Rake command - ruby-on-rails

I am trying to use the Ruby on Rails Rake command to migrate to an Oracle database. My database.yml file contains the following:
development:
adapter: oracle
database: album_development
sid: orc1
username: system
password: root
On my PC I have set ORACLE_SID=orcl.
When I run Rake,migrate, I get the following error:
rake aborted!
The driver encountered an error: java.sql.SQLException: Listener refused the connection with the following error:
ORA-12505, TNS:listener does not currently know of SID given in connect descriptor
Can you tell me if I need to modify my listener.ora file to get this to work? My listener.ora file is as follows:
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = PLSExtProc)
(ORACLE_HOME = C:\oraclexe\app\oracle\product\11.2.0\server)
(PROGRAM = extproc)
)
(SID_DESC =
(SID_NAME = CLRExtProc)
(ORACLE_HOME = C:\oraclexe\app\oracle\product\11.2.0\server)
(PROGRAM = extproc)
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1))
(ADDRESS = (PROTOCOL = TCP)(HOST = Lenovo-PC)(PORT = 1521))
)
)
DEFAULT_SERVICE_LISTENER = (XE)
The output of the lsnrctl Status command is as follows:
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for 32-bit Windows: Version 11.2.0.2.0 - Production
Start Date 21-APR-2016 11:14:15
Uptime 0 days 0 hr. 7 min. 43 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Default Service XE
Listener Parameter File C:\oraclexe\app\oracle\product\11.2.0\server\network\admin\listener.ora
Listener Log File C:\oraclexe\app\oracle\diag\tnslsnr\Lenovo-PC\listener\alert\log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(PIPENAME=\\.\pipe\EXTPROC1ipc)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=Lenovo-PC)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=Lenovo-PC)(PORT=8080))(Presentation=HTTP)(Session=RAW))
Services Summary...
Service "CLRExtProc" has 1 instance(s).
Instance "CLRExtProc", status UNKNOWN, has 1 handler(s) for this service...
Service "PLSExtProc" has 1 instance(s).
Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) for this service...
Service "XEXDB" has 1 instance(s).
Instance "xe", status READY, has 1 handler(s) for this service...
Service "xe" has 1 instance(s).
Instance "xe", status READY, has 1 handler(s) for this service...
The command completed successfully
Can anyone help / make a suggestion?

firstly you can check the database is accessible by using the TNSPING command
e.g: TNSPING xe
could it be you have used a one rather than an L sid: orc1 should be sid: orcl perhaps ?

Kevin,
Thanks for your help. I changed my database.yml to:
development:
adapter: oracle
database: xe
username: system
password: root
This allowed me to connect to the database. I now have another problem, but I think I can tackle that one. Kind regards, Sean

Related

Configuring Backup gem in Rails 5.2 - Performing backup of PostgreSQL database

I would like to perform a regular backup of a PostgreSQL database, my current intention is to use the Backup and Whenever gems. I am relatively new to Rails and Postgres, so there is every chance I am making a very simple mistake...
I am currently trying to setup the process on my development machine (MAC), but keep getting an error when trying to connect to the database.
In the terminal window, I have performed the following to check the details of my database and connection:
psql -d my_db_name
my_db_name=# \conninfo
You are connected to database "my_db_name" as user "my_MAC_username" via socket in "/tmp" at port "5432".
\q
I have also manually created a backup of the database:
pg_dump -U my_MAC_username -p 5432 my_db_name > name_of_backup_file
However, when I try to repeat this within db_backup.rb (created by the Backup gem) I get the following error:
[2018/10/03 19:59:00][error] Model::Error: Backup for Description for db_backup (db_backup) Failed!
--- Wrapped Exception ---
Database::PostgreSQL::Error: Dump Failed!
Pipeline STDERR Messages:
(Note: may be interleaved if multiple commands returned error messages)
pg_dump: [archiver (db)] connection to database "my_db_name" failed: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/tmp/pg.sock/.s.PGSQL.5432"?
The following system errors were returned:
Errno::EPERM: Operation not permitted - 'pg_dump' returned exit code: 1
The contents of my db_backup.rb:
Model.new(:db_backup, 'Description for db_backup') do
##
# PostgreSQL [Database]
#
database PostgreSQL do |db|
# To dump all databases, set `db.name = :all` (or leave blank)
db.name = "my_db_name"
db.username = "my_MAC_username"
#db.password = ""
db.host = "localhost"
db.port = 5432
db.socket = "/tmp/pg.sock"
# When dumping all databases, `skip_tables` and `only_tables` are ignored.
# db.skip_tables = ["skip", "these", "tables"]
# db.only_tables = ["only", "these", "tables"]
# db.additional_options = ["-xc", "-E=utf8"]
end
end
Please could you suggest what I need to do to resolve this issue and perform the same backup through the db_backup.rb code
In case someone else gets stuck in a similar situation, the key to unlocking this problem was the lines:
psql -d my_db_name
my_db_name=# \conninfo
I realised that I needed to change db.socket = "/tmp/pg.sock" to db.socket = "/tmp", which seems to have resolved the issue.
However, I don't understand why the path on my computer differs to the default as I didn't do anything to customise the installation of any gems or the Postgres App

ORA-12547: TNS:lost contact

I downloaded a docker container with oraclexe 11g on Ubuntu 14.
Everything worked as expected, i created tables, insert data, etc and then i commit the container, generating a new image(same oracle image, but with my tables and data).
Problem:
I canĀ“t connect to my database in my newly created image, either local or remote.
Any tips on that error?
Oracle image:
https://hub.docker.com/r/sath89/oracle-xe-11g/
**sqlplus / as sysdba
SQL*Plus: Release 11.2.0.2.0 Production on Fri May 6 20:13:43 2016
Copyright (c) 1982, 2011, Oracle. All rights reserved.
ERROR:
ORA-12547: TNS:lost contact**
listener.ora
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = PLSExtProc)
(ORACLE_HOME = /u01/app/oracle/product/11.2.0/xe)
(PROGRAM = extproc)
)
(SID_DESC =
(SID_NAME = XE)
(ORACLE_HOME = /u01/app/oracle/product/11.2.0/xe)
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC_FOR_XE))
(ADDRESS = (PROTOCOL = TCP)(HOST = e68b846e86b8)(PORT = 1521))
)
)
tnsnames.ora
# tnsnames.ora Network Configuration File:
XE =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = e68b846e86b8)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = XE)
)
)
EXTPROC_CONNECTION_DATA =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC_FOR_XE))
)
(CONNECT_DATA =
(SID = PLSExtProc)
(PRESENTATION = RO)
)
)
lsnrctl status
LSNRCTL for Linux: Version 11.2.0.2.0 - Production on 06-MAY-2016 20:11:55
Copyright (c) 1991, 2011, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC_FOR_XE)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 11.2.0.2.0 - Production
Start Date 06-MAY-2016 20:11:22
Uptime 0 days 0 hr. 0 min. 32 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /u01/app/oracle/product/11.2.0/xe/network/admin/listener.ora
Listener Log File /u01/app/oracle/product/11.2.0/xe/log/diag/tnslsnr/e68b846e86b8/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC_FOR_XE)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=e68b846e86b8)(PORT=1521)))
Services Summary...
Service "PLSExtProc" has 1 instance(s).
Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) for this service...
Service "XE" has 1 instance(s).
Instance "XE", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully
lsnrctl services
LSNRCTL for Linux: Version 11.2.0.2.0 - Production on 06-MAY-2016 20:12:34
Copyright (c) 1991, 2011, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC_FOR_XE)))
Services Summary...
Service "PLSExtProc" has 1 instance(s).
Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) for this service...
Handler(s):
"DEDICATED" established:0 refused:0
LOCAL SERVER
Service "XE" has 1 instance(s).
Instance "XE", status UNKNOWN, has 1 handler(s) for this service...
Handler(s):
"DEDICATED" established:0 refused:0
LOCAL SERVER
The command completed successfully
The problem is with the dockerfile mounting the oracle data folder
VOLUME "/u01/app/oracle"
When i commit my container, this folder is not saved into my new image, generating the errors to start the db.

Ruby Sequel AS/400 connection issues

I need to connect to a AS/400 system using ODBC connection, and I'm using the Ruby sequel gem. My environment is just Ubuntu 14.04 running in virtual box. I'm able to run isql -v my.host.com and drop in to a sql console. When I try and do this from IRB, I get the error message.
require 'sequel'
db = Sequel.odbc(:drvconnect=>'driver={IBM i Access ODBC Driver};system=my.host.com;database=MYDBNAME;uid=MYUSERNAME;password=MYPASSWORD;DefaultLibraries=, *usrlibl;authentication=server')
tables = db[:QSYS2__SYSTABLES].where("TABLE_NAME like ?", "SYS%")
tables.each do |record|
puts record[:table_name]
end
#=> Sequel::DatabaseConnectionError: ODBC::Error: IM002 (0) [unixODBC][Driver Manager]Data source name not found, and no default driver specified
from /home/vagrant/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/sequel-4.32.0/lib/sequel/adapters/odbc.rb:21:in `drvconnect'
from /home/vagrant/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/sequel-4.32.0/lib/sequel/adapters/odbc.rb:21:in `connect'
from /home/vagrant/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/sequel-4.32.0/lib/sequel/connection_pool.rb:103:in `make_new'
from /home/vagrant/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/sequel-4.32.0/lib/sequel/connection_pool/threaded.rb:224:in `make_new'
from /home/vagrant/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/sequel-4.32.0/lib/sequel/connection_pool/threaded.rb:197:in `available'
from /home/vagrant/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/sequel-4.32.0/lib/sequel/connection_pool/threaded.rb:133:in `_acquire'
from /home/vagrant/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/sequel-4.32.0/lib/sequel/connection_pool/threaded.rb:147:in `block in acquire'
from /home/vagrant/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/sequel-4.32.0/lib/sequel/connection_pool/threaded.rb:265:in `block in sync'
from /home/vagrant/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/sequel-4.32.0/lib/sequel/connection_pool/threaded.rb:265:in `synchronize'
from /home/vagrant/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/sequel-4.32.0/lib/sequel/connection_pool/threaded.rb:265:in `sync'
from /home/vagrant/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/sequel-4.32.0/lib/sequel/connection_pool/threaded.rb:146:in `acquire'
from /home/vagrant/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/sequel-4.32.0/lib/sequel/connection_pool/threaded.rb:104:in `hold'
from /home/vagrant/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/sequel-4.32.0/lib/sequel/database/connecting.rb:251:in `synchronize'
from /home/vagrant/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/sequel-4.32.0/lib/sequel/adapters/odbc.rb:44:in `execute'
from /home/vagrant/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/sequel-4.32.0/lib/sequel/dataset/actions.rb:952:in `execute'
from /home/vagrant/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/sequel-4.32.0/lib/sequel/adapters/odbc.rb:97:in `fetch_rows'
from /home/vagrant/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/sequel-4.32.0/lib/sequel/dataset/actions.rb:141:in `each'
I'm not familiar at all with AS/400 or using ODBC connections, but if isql works then maybe it's a user permission error?
Here is my /etc/odbc.ini
[my.host.com]
Description = IBM i Access ODBC Driver
Driver = IBM i Access ODBC Driver
System = my.host.com
UserID = MYUSERNAME
Password = MYPASSWORD
Naming = 1
DefaultLibraries = *usrlibl;
Database = MYDBNAME
I should also mention that the AS/400 system is located remotely at the my.host.com, so I'm not trying to connect to some local running service. I am able to ping the IP address of that host though.
Edit: I've changed my driver in the drvconnect to match what's in the odbc.ini as per the suggestion below. Also I should note that I have a /etc/odbcinst.ini file with the following
[IBM i Access ODBC Driver]
Description = IBM i Access for Linux ODBC Driver
Driver = /opt/ibm/iaccess/lib/libcwbodbc.so
Setup = /opt/ibm/iaccess/lib/libcwbodbcs.so
Driver64 = /opt/ibm/iaccess/lib64/libcwbodbc.so
Setup64 = /opt/ibm/iaccess/lib64/libcwbodbcs.so
Threading = 0
DontDLClose = 1
UsageCount = 1
[IBM i Access ODBC Driver 64-bit]
Description = IBM i Access for Linux 64-bit ODBC Driver
Driver = /opt/ibm/iaccess/lib64/libcwbodbc.so
Setup = /opt/ibm/iaccess/lib64/libcwbodbcs.so
Threading = 0
DontDLClose = 1
UsageCount = 1
You have this:
require 'sequel'
db = Sequel.odbc(:drvconnect=>'driver={iSeries Access ODBC Driver}; system=my.host.com;...
But then you show this:
[my.host.com]
Description = IBM i Access ODBC Driver
Driver = IBM i Access ODBC Driver
If you actually have the IBM i Access ODBC Driver, Then that's what you should reference in your code, rather than iSeries Access ODBC Driver.
Figured it out! It turns out that when you have your /etc/odbc.ini defined with all your connection info, you don't need a connection string.
require 'sequel'
db = Sequel.odbc(drvconnect: '')
tables = db[:QSYS2__SYSTABLES].where("TABLE_NAME like ?", "SYS%")
tables.each { |r| puts r[:table_name] }
This query takes a stupid long time to run on my machine, but it does return all tables that start with "SYS". The only change I did need to make to my /etc/odbc.ini for this to work was to rename the DSN to "default"
[default]
Description = IBM i Access ODBC Driver
Driver = IBM i Access ODBC Driver
System = my.host.com
UserID = MYUSERNAME
Password = MYPASSWORD
Naming = 1
DefaultLibraries = *usrlibl;
Database = MYDBNAME
Just for anyone else that may run into this issue, here are a few other things I did along the way to get things working. My setup is Ubuntu 14.04
Install unixodbc and unixodbc-dev
My my.host.com needed to be added to my /etc/hosts since it didn't resolve on public DNS.
The driver filename I installed is called ibm-iaccess-1.1.0.4-1.0.amd64.deb
running ldd /opt/ibm/iaccess/lib64/libcwbodbc.so showed that there was a missing symlink.`
Added missing symlink for /usr/lib/x86_64-linux-gnu/libodbcinst.so.1 to /usr/lib/x86_64-linux-gnu/libodbcinst.so.2
That's it. Hope that helps other people too.

Can't connect java client to Marklogic database

I've just installed a MarkLogic nosql database out of the box on a windows machine.
I wrote a simple javaclient to put data in to the database but I get this error:
org.apache.http.conn.HttpHostConnectException: Connection to http://my.caci.local:8003 refused
at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:158)
The Marklogic database is started. This is the code :
DatabaseClient client = DatabaseClientFactory.newClient("localhost", 8003, "admin", "admin", Authentication.DIGEST);
XMLDocumentManager docMgr = client.newXMLDocumentManager(); BinaryDocumentManager binMgr = client.newBinaryDocumentManager();
DOMHandle handle = new DOMHandle(); for (int i = 0; i < AANT_PERSONEN; i++) {
Document document = createDocument(i);
String docId = "/zaak/" + 20;
handle.set(document);
docMgr.write(docId, handle); }
....
The Marklogic console reports the following ports to be active on my.caci.local:
Default :: Admin : 8001 [HTTP]
Default :: App-Services : 8000 [HTTP]
Default :: HealthCheck : 7997 [HTTP]
Default :: Manage : 8002 [HTTP]
I'm new to marklogic and this is my question:
- what port should I use to connect to from my java client?
In agreement with MystyxMac, I notice the console does not report a REST server on 8003.
Here's the documentation for setting up a REST server:
http://docs.marklogic.com/guide/rest-dev/intro#id_97899
You should also add users for the rest-reader, rest-writer, and rest-admin roles.
Hoping that helps,
Erik Hennum
For testing purposes you can simply switch the port you are using to 8000.
From the documentation:
When you install MarkLogic Server, a pre-configured REST API instance
is available on port 8000. This instance uses the Documents database
as the content database and the Modules database as the modules
database.
The instance on port 8000 is convenient for getting started, but you
will usually create a dedicated instance for production purposes.
http://docs.marklogic.com/guide/rest-dev/service#id_15309

Lua programming ,error in establishing Database connection

After writing the code to connect to database,lua returns an error as
Error in establishing connection to MySQL ,Can't connect to /var/lib/mysql/mysql.sock
I'm unable to locate the /var/lib/mysql/mysql.sock file (which I haven't created )
My Sock is /tmp/mysql.sock
Below is my code to connect to MySQL database.
mysql = require "luasql.mysql"
local env = mysql.mysql()
local conn = env:connect('test','root','')
print(env,conn)
status,errorString = conn:execute([[CREATE TABLE sample2 (id INTEGER, name TEXT);]])
print(status,errorString )
as seen there: Luasql error: "LuaSQL: error connecting to database", the problem is because luasql defaults to using a default socket path when connecting to localhost without a port. so just set the mysql host and port in env:connect or specify the socket path.
EDIT:
I believe your code should be:
env:connect('test','root','','localhost',3306) -- for tcp
-- or
env:connect('test','root','',':/tmp/mysql.sock') -- for socket

Resources