I'm using oracledb with Node and ExpressJS to develop my app. In localhost, I have no problems in my connections, but I need to configure the project in a server that connects to the database that it's in other server. When I do that, I get the error (Translated from spanish):
Error: Error: ORA-12154: TNS: the specified connection identifier could not be resolved.
This is my configuration code:
const oracleDbConfig = {
user: "myUser",
password: "myPassword",
connectString: "192.168.6.129:1521/myDatabase",
}
Also, if I install my project in the database server and I run the same configuration using localhost, it works with no problem:
const oracleDbConfig = {
user: "myUser",
password: "myPassword",
connectString: "localhost:1521/myDatabase",
}
Please, help me to understand the error.
Troubleshooting:
NetworkCheck: Is your dbnode reachable? : dig,ping,host,nslookup
FirewallCheck: Can you connect to the dbnode oracle listener? nc -vz dbnode 1521
ServiceCheck: Is the database service myDatabase exposed in listener on dbnode? dbnode>$lsnrctl status | grep myDatabase
If you can mark these tree points a success, you should be able to connect.
Best of luck.
I solved the problem changing the connection string as the documentation says:
const oracleDbConfig = {
user: "myUser",
password: "myPassword",
connectString: "(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.6.129)(PORT=1521))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=myDatabase)))"
}
Both ways are valid, but I only have made it work with this.
Related
I am using the free subscription at Azure and have successfully created a Ubuntu Server and a Flexible Postgres Database.
Until recently I accessed the DB directly from my Windows 10 desktop. Now I want to route all access through the Ubuntu Server.
For this I have installed Open SSH Client and Open SSH Server on my Windows 10 machine and done the necessary local port forwarding with ssh -L 12345:[DB IP]:5432 my_user#[Ubuntu IP]
The connection works, I confirmed it with pgcli on my desktop with pgcli -h 127.0.0.1 -p 12345 -u my_user -d my_db
But when I am trying to connect via node-pg I receive the following error
UnhandledPromiseRejectionWarning: error: no pg_hba.conf entry for host "[Ubuntu IP]", user "my_user", database "my_db", SSL off
I have already added a Firewall Rule in Azure with the [Ubuntu IP], and the error remains. What bugs me further is that in the Azure Portal of the DB I have enabled "Allow public access from any Azure service within Azure to this server", so the extra Firewall should not even be necessary for this connection.
For the last week, I have been stuck on this and now the connection is finally established, but not accessible by my code. Pretty frustrating. I would be glad about ANY pointers on how to fix this.
Edit #1:
I can't post the pg_hba.conf file. Because the Postgres DB is managed by Azure, I do not have access to pg_hba, which makes the situation more difficult to understand.
My node.js code for testing the connection:
const pg = require("pg");
const passwd = "...";
const client = new pg.Client({
user: 'admin',
host: '127.0.0.1',
database: 'test',
password: passwd,
port: 12345
});
client.connect()
client.on('uncaughtException', function (err) {
console.error(err.stack);
});
const query = "SELECT * FROM test";
try {client.query(query, (err,res) => {
if (err) {
console.error(err);
}
console.log(res);
})}
catch (e) {
console.error(e)
}
The comment by #jjanes helped me in understanding the issue, thank you.
This edited pg.Client config solved my problem:
const client = new pg.Client({
user: 'admin',
host: '127.0.0.1',
database: 'test',
password: passwd,
port: 12345,
ssl: {rejectUnauthorized: false}
});
I found this specific SSL option here https://node-postgres.com/features/ssl
I can connect fine with SQL Server Management Studio, but not with Node.
I am using the mssql npm package.
Here's the node connection.
db: {
server: "123.456.789.255\\WEBSQL",
database: "db_name",
user: "user",
password: "pass"
}
I am getting a ETIMEOUT error.
ConnectionError: Failed to connect to 123.456.789.255\\WEBSQL in 15000ms
Can anyone point me to the right direction?
Adding this fixed the problem.
options: {
encrypt: false,
},
This was working the last time I looked at it. The code remains unchanged.
I have an SSH tunnel through an ec2 instance to an Aurora Postgres DB. I can connect to it through psql. I can also connect to it through Datagrip. I'm able to run queries.
But using the exact same connection settings through nodejs I get a connection timeout. The connection settings are exactly the same as the ones I'm using in psql and Datagrip.
pool = new Pool({
user: "myuser",
host: "localhost",
database: 'somedb',
password: "password",
port: 1234
});
pool.query('SELECT column1, column2 FROM test ORDER BY id ASC', (error, results) => {
if (error) {
response.status(400).send(`Error: ${error.message}`);
return;
}
response.status(200).json(results.rows);
})
The same code works on the server directly. It just no longer works when trying to connect via ssh tunnel. (although it used to work)
The problem was the version of the pg npm package. I updated to a newer package and the connection started working again.
I have been having some trouble with connecting my node.JS app to my Heroku database. I had my app working with a locally hosted Postgres database on PGadmin, but when I tried moving towards deploying on Heroku with a Heroku Postgres DB I started getting a variety of errors.
This was my base code that worked locally and that I tried to switch over to Heroku's DB (some variables hidden with ***):
const Client = require('pg');
const client = new Client.Client({
host: "***.amazonaws.com",
user: "***",
password: "***",
database: "***",
port: 5432,
ssl: true,
sslmode: require,
});
The "ssl" and "sslmode" were only added when switching over.
I have triple-checked that all the values are correct. When I do it this way this is the error I get...
Error: self signed certificate
When commenting out the "ssl" part the error changes to...
Error: no pg_hba.conf entry for host '***', user '***', database '***' , SSL off
I tried researching this pg_hba.conf issue and there was suggestions I add in a line that made sure that a password was not required for all IPv4 connections but this did not change my error messages.
I am quite a bit stuck on how to solve this trouble as I can't quite find any further help online so far.
I'm trying to connect an Express app to MariaDB, both running on localhost.
I have the following code in an Express app:
const mariadb = require('mariadb');
const pool = mariadb.createPool({
user: 'testuser',
password: 'password',
database: 'test',
connectionLimit: 5
});
I can connect using 'testuser' from the MariaDB command line, but when Express executes the code above, I see the following in the console:
SQLError: (conn=63, no: 1698, SQLState: 28000) Access denied for user 'testuser'#'localhost'
...
code: 'ER_ACCESS_DENIED_NO_PASSWORD_ERROR'
I have tried setting the testuser password to ''. Have also tried using root user credentials. I always get the same NO_PASSWORD error.
I am running this in Ubuntu 18.04 within Windows Subsystem for Linux/WSL.
Any help is appreciated.