NodeJS oracledb - ORA-03135: connection lost contact - javascript

I have a NodeJS application which uses oracledb library to connect to an Oracle Database . It's using the following code to try to connect to the database:
this.oracledb.fetchAsBuffer = [this.oracledb.BLOB];
const dbconfig = {
user: 'mysuser',
password: 'mypass',
connectString: '10.xxx.xx.xxx/MYORCLID'
};
console.log("Trying to get connection");
return await this.oracledb.getConnection(dbconfig);
But, I'm receiving the following error now during the "getConnection" method:
"Error: ORA-03135: connection lost contact"
Please, is there anything wrong with this code? It was working before but suddenly I started to receive the above message. From where should I start to check?
I've tried telnet and it worked too, so I'm not sure if this is a firewall issue.

I managed to solve the issue.
It was an internal blocking issue inside our network. They use a type of application which checks the origin hostname, linux user, application name and other properties before allowing access to the database.
After talking to my Infra and DB Team, they checked and liberated the access, and then everything worked as it should.
Thanks!

Related

"WebSocket connection to 'wss://mydomain.com:8080/' failed:" with no extra details

I am trying to host a websocket using node.js and it seems to host fine, but I cannot connect to it externally because I just get the error in the title. The : after failed suggests there should be extra details and similar questions here prove that, but I'm not getting anything after the colon making this very difficult to debug. I have tried in multiple browsers and I get the same error so it's not my browser causing this. My best guess would be that my cerificates aren't working, but they're the same certificates I use for the rest of my websites and they work fine for them so not too sure.
This is my server-side (node.js) code:
const server = require('https').createServer({
cert: fs.readFileSync('/etc/letsencrypt/live/mydomain.com/fullchain.pem'),
key: fs.readFileSync('/etc/letsencrypt/live/mydomain.com/privkey.pem')
});
const websocket = new (require('ws').Server)({server});
websocket.on('connection', (client, request) => {
console.log("New connection from "+request.socket.remoteAddress);
});
And my client-side (Javascript) code is just
new WebSocket("wss://mydomain.com:8080").onmessage = (event) => {
console.log(event.data);
};
I have tried making my node.js server listen to port 8080 but that made no difference. I have also tried different URLs on the client side (such as without the protocol, without the port, using my ip) but as I would expect, those don't work either.

Google apps script connection problem with SQL Server

I have a problem in Google apps script connecting to a SQL Server database. Here is the code:
//Function to connect to ms sql server
function conn_test_server(){
var conn = Jdbc.getConnection("jdbc:sqlserver:\\ipaddress\instance:port",
"username", "password!");
}
//String formats i have used
//"jdbc:sqlserver://ipaddress:port/database"
//"jdbc:sqlserver:\\ipaddress\instance:port"
When I tried it an error is thrown that tells my to check the connection string, username and password.
I have triple checked them, as well the port seems open as I can connect through another app and also have whitelist the required IP's so the firewall does not stop them to connecting.
Please, if you could tell me other things I can look into to solve this error I would be very grateful.

Not connecting to database with node.js

I'm trying to connect and request queries from my database, but I wanna do it with JavaScript (or jQuery).
I'm trying this:
var mysql = require('mysql');
var con = mysql.createConnection({
host: "localhost",
user: "myUser",
password: "myPassword",
database: "mydb"
});
function GetSqlResult (sql_query) {
con.connect(function(err) {
if (err) throw err;
//Select all customers and return the result object:
con.query(sql_query, function (err, result, fields) {
if (err) throw err;
return result;
});
});
};
But I get this error:
Uncaught ReferenceError: require is not defined
I've tried using using the module "require.js" from this website http://requirejs.org/docs/release/2.2.0/minified/require.js
I still got the same error.
I want a solution for this error (if it exists), not an alternative.
I know that connecting to a database from JavaScript isn't very safe, but I really wanna do it, so I would love for someone to help me, please.
Thank you
What you are trying to do without knowing it, is build a RESTful API. In web architecture, you have your front end code (browser javascript) which makes HTTP requests to a backend. That backend will connect to the database and run queries. Even if you wanted to do this from browser javascript, your browser wouldn't let you. I would recommend you write a REST Api using NodeJS, and have your browser javascript make HTTP requests to that backend. Hope this helps.
NodeJS is not jquery, nodeJs it runs on a backend web server.
you can use Meteor for connecting to database from the client side.

Issues connecting to Amazon RDS Postgres database on node.js using sequelize ORM

I'm currently working on migrating an environment set up in Heroku over to the Amazon Web Services stack (RDS PostgreSQL, Elastic Beanstalk).
I'm facing some issues when trying to connect to PostgreSQL through the sequelize.js ORM. Error message below:
Unhandled rejection SequelizeHostNotFoundError: getaddrinfo ENOTFOUND
[host].
I can connect to the database through pgAdmin so I know the service is working, and the following configuration has worked on Heroku:
sequelize = new Sequelize(process.env.DATABASE_URI, {
dialect: 'postgres',
protocol: 'postgres',
logging: true,
timestamps: false
})
DATABASE_URI is formatted in the following way:
postgres://[db_username]:[db_password]#[hostname]:[port]/[db_name]
Any help would be greatly appreciated. Thanks in advance!
I was able to solve my issues here. Essentially, I solved it by setting up the following correctly within the environment.:
Formatting URI correctly - (Following the syntax above, I was able to get it to work)
Enabling security provisions for Amazon RDS & Elastic Beanstalk - I had to enable Inbound access to the Amazon RDS instance for the Security group / Instance Role that the Elastic Beanstalk was running under. (I got caught up in the fact that I was able to hit RDS through my local computer. By default, it seems RDS sets up the IP that you are using to be able to use it... which makes sense..)
I had a very similar problem, and it turned out I had a question mark in my password — causing half the password and the remainder of the connection URL to be ignored (as apparently part of the URL search portion).
Something like:
new Sequelize("postgres://fred:xj78?23#example.com/db");
Where we end up with username: fred, password: xj78, and everything else blank.
Escaping the question mark as %3F fixes the issue.

Getting my Mongo connection string correct for remote database hosting with auth

I'm having trouble attempting to replicate this MongoDB connection in NodeJS, using Mongojs:
mongo --host dds-xxxx.mongodb.rds.aliyuncs.com:3717 -u root -p password --authenticationDatabase admin
My current, rather obfuscated, code:
/* MongoDB setup */
// Set parameters:
var aliUser = 'root',
aliPass = 'password',
aliHost = 'dds-xxxx.mongodb.rds.aliyuncs.com:3717',
aliAuth = 'admin',
aliMyDb = 'mydb';
// Initialise MongoDB object:
var connectionString = aliUser+':'+aliPass+'#'+aliHost+'/'+aliMyDb+'?authSource='+aliAuth,
db = mongojs(connectionString, ['keywords']);
As far as I can tell, this is not connecting correctly. The code never seems to give any errors or alert the user in any way as to whether or not the connection was successful. However, the GET methods I have which try to read from this database produce no result, so it doesn't appear to work.
I have tried several variations on this and can't quite seem to get it right. Any assistance or insight would be greatly appreciated.
Thanks again.
Add 'mongodb://' to your connection string. The examples given for mongojs needs update.
As it turns out, there was nothing wrong with my code at all! The problem was that my server provider, Aliyun, can only be accessed from its own whitelisted servers. So I had to run my Node app from one of their servers to make it work!
This is fine since we are hosting on Aliyun anyway, but I was testing on local, therefore it appeared not to work! Another mystery solved.

Categories