SQL Server connection using tedius and sequelize in NodeJs - javascript

Getting below error when trying to connect SQL Server Local database in NodeJs Sequelize.
name: 'SequelizeHostNotFoundError',
message: 'Failed to connect to abcdd\SQL2K12:1433 - getaddrinfo ENOTFOUND abcdd\SQL2K12',
code: 'ESOCKET
Below are my configuration settings and the credentials are correct
"use_env_variable": false,
"username": "username",
"password": "password#123",
"database": "db_test",
"host": "abcdd\\SQL2K12", //actual db hotsname is abcdd\SQL2K12
"dialect": "mssql",
"operatorsAliases": false,
"dialectOptions": {
"encrypt": true,
"trustedConnection": true
}
In SSMS its working fine. And is there issue with port number? As I am not using a port in SSMS.

For me works adding instanceName instead of putting server: 'SERVER\SQLSERVER2K06',
just put "SERVER".
var config = {
server: 'SERVER',
authentication: {
type: 'default',
options: {
userName: 'user',
password: '*****'
}
},
options: {
database: 'NAME',
instanceName: 'SQLSERVER2K06' /*It Works! */
}
}

for tedious:
options.instanceName
The instance name to connect to. The SQL Server Browser service must be running on the database server, and UDP port 1434 on the database server must be reachable.
(no default)
Mutually exclusive with options.port.
check the comments:
https://github.com/tediousjs/node-mssql/issues/130
var config = {
userName: 'test01',
password: 'test01',
server: 'localhost',
options: {
"database":"TestDB",
"instanceName": "SQL2012"
}
};
in your case
var config = { server: 'abcdd', options: {"instanceName": "SQL2K12" } };
Also, make sure TCP enabled on your SQL Server: Sql Server Configuration Manager > SQL Server Network Configuration > Protocols for SQLSERVER > TCP/IP

Related

ssh2 node js sftp protocol Error Handshake failed

Hello i have a little problem, i developped a script sftp client with node js that connect to an sftp server and grab some files, i tested it with my local server its working, but when i tried to use it with production server i received this error :
Error: Handshake failed: no matching key exchange algorithm
i already generated the rsa key using ssh-keygen
here is the relevant part of the script :
var Client = require('ssh2').Client;
var fs = require('fs');
var path = require('path');
var args = process.argv.slice(2);
var connSettings = {
host: args[0] || '127.0.0.1',
port: args[1] || 22,
username: args[2] || 'karim',
password: args[3] || 'karimos',
algorithms: {
hmac: ['hmac-sha2-256', 'hmac-sha2-512', 'hmac-sha1', 'hmac-sha1-96']
}
};
I also had the same problem and solved it by adding the following:
algorithms: {
kex: [
"diffie-hellman-group1-sha1",
"ecdh-sha2-nistp256",
"ecdh-sha2-nistp384",
"ecdh-sha2-nistp521",
"diffie-hellman-group-exchange-sha256",
"diffie-hellman-group14-sha1"
],
cipher: [
"3des-cbc",
"aes128-ctr",
"aes192-ctr",
"aes256-ctr",
"aes128-gcm",
"aes128-gcm#openssh.com",
"aes256-gcm",
"aes256-gcm#openssh.com"
],
serverHostKey: [
"ssh-rsa",
"ecdsa-sha2-nistp256",
"ecdsa-sha2-nistp384",
"ecdsa-sha2-nistp521"
],
hmac: [
"hmac-sha2-256",
"hmac-sha2-512",
"hmac-sha1"
]
}
For myself, I added debug: console.log to my config object. This output more about the connection attempt.
{
"port": 22,
"host": "test.test.com",
"user": "test",
"password": "******",
"debug": console.log
}
Handshake: (remote) KEX method: diffie-hellman-group14-sha1,diffie-hellman-group-exchange-sha1
Handshake: No matching key exchange algorithm
Based on this error I updated my config's algorithm:
{
"port": 22,
"host": "test.test.com",
"user": "test",
"password": "******",
"algorithms": {
"kex": [
"diffie-hellman-group14-sha1","diffie-hellman-group-exchange-sha1"
]
}
}
After adding this algorithm the connection was successful on my machine
You may edit your /etc/ssh/sshd configuration file, on your server, in order to allow the key authentication method :)
My first suggestion would be to upgrade the ssh server on the server you're connecting to so that a more secure configuration can be had. This is the best/most secure solution.
If you cannot make changes on this server and you absolutely need to connect, then you can explicitly set the kex to a list of key exchange methods you want to support (valid algorithm names can be found in the ssh2-streams documentation). For example:
algorithms: {
kex: [ ... ]
}
Have you tried changing your algorithms declaration to...?
algorithms: {
serverHostKey: [ 'hmac-sha2-256', 'hmac-sha2-512', 'hmac-sha1', 'hmac-sha1-96' ],
}

How Do i connect sails to mongodb?

Im new to sails Js and mongodb. I am absolutely a newbie.
Problem:
I already have a user collection on my mongodb database. I want to connect it to sails to display the list of collection.
Ive seen sails js documentations. I already installed sails-mongo adapter and edited the connection.js....
module.exports = {
// this is my model
attributes: {
firstname: {
type: 'string'
}
},
findUser: function(opts,callback){
///// How am I going to connect to mongo and query the users ?
//// user.find('John Doe') wont work here.
}
}
Run: npm install sails-mongo
in config/connections.js uncomment section related to mongo and enter necessary info there
someMongodbServer: {
adapter: 'sails-mongo',
host: 'mongohost.com',
port: 55915,
user: 'user',
password: 'password',
database: 'dbname'
},
in config/models.js enter you connection adapter variable
...
connection: 'someMongodbServer',
...
done
EDIT:
In order to get the data from database use the following:
User.find({firstname: 'John Doe'}).exec(function(error, user) {
console.log(user);
});

Sails js: How can I define two MySQL connections to two different databases in a single model in Sails js?

I have created a model Employee.js and EmployeeController.js. I have defined two connections in Employee.js file:
module.exports = {
connection: 'LocalhostMysqlServer',
attributes: {
name:{
type:"string",
required:true,
},
empnum:{
type:"integer",
required:true,
unique: true
},
email:{
type:"string",
required:true,
unique: true
}
},
connection: 'LocalhostMysqlServer1',
attributes: {
username:{
type:"string",
required:true,
},
usrnum:{
type:"integer",
required:true,
unique: true
},
email:{
type:"string",
required:true,
unique: true
}
},
};
Below is my EmployeeController.js file where I have included two views: CreateEmp & CreateUsr, associated with this Model and controller. Also, I have defined two functions to handle the post requests from these views. Here, I want to insert the data from CreateEmp to a different database and from CreateUsr to a different database.
module.exports = {
createEmp: function(req,res){
'use strict';
res.view('new.ejs');
},
createUsr: function(req,res){
'use strict';
res.view('newUser.ejs');
},
createEmployee: function(req, res){
if(req.method=="POST"){
var name= req.param("name");
var empnum= req.param("empnum");
var email= req.param("email");
var insert= "INSERT INTO employee(name, empnum, email) VALUES ('"+name+"', "+empnum+", '"+email+"')";
Employee.query(insert, function(err, record){
if(err)
console.log(err);
else{
console.log(record);
}
})
}
},
createUser: function(req, res){
if(req.method=="POST"){
var username= req.param("username");
var usrnum= req.param("usrnum");
var email= req.param("email");
var insert= "INSERT INTO user (username, usrnum, email) VALUES ('"+username+"', "+usrnum+", '"+email+"')";
Employee.query(insert, function(err, record){
if(err)
console.log(err);
else{
console.log(record);
}
})
}
},
};
I have included my config/connections.js here:
module.exports.connections = {
localDiskDb: {
adapter: 'sails-disk'
},
LocalhostMysqlServer: {
adapter: 'sails-mysql',
//module: 'sails-mysql',
host: 'localhost',
user: 'root',
password: 'disisanshu',
database: 'sailsTest1',
tableName: 'employee'
},
LocalhostMysqlServer1: {
adapter: 'sails-mysql',
host: 'localhost',
user: 'root',
password: 'disisanshu',
database: 'sailsTest2',
tableName: 'user'
}
};
Here I have included my model.js below:
module.exports.models = {
// migrate: 'alter'
connection: 'LocalhostMysqlServer',
migrate: 'alter',
connection1: 'LocalhostMysqlServer1',
migrate: 'alter'
};
There is no reason why you should do such a thing.
You are probably looking to reduce your load on your database. A master-slave database kind of structure should be implemented instead.
Also, the database should be totally de-coupled from the rest of your app.That is why you should have only one connection.
If the load on your database increases, scale it horizontally (add more servers to distribute the load)- mySQL is good for these things. This can and should be done without any change in your app code.
You can't use two different connections in the same model--hopefully there's no documentation that says this is possible! You'll just have to define two different models.
Also, it's not really valid Javascript to declare the same key twice in an object (as you do with connection in your first code block, and with migrate in your last). The second definition will just override the first if they're different.

How to execute Orientdb server side function from Orientjs?

I am using Orientjs to access a Orientdb database from a nodejs script, but the server side function does not effect the database.
Server side script:
This Javascript function addTxt() takes the argument author and text
var db = orient.getGraph();
db.command('sql','insert into Message (author, text) VALUES ("'+author+'", "'+text+'")');
return "1";
Query: This function has been tested in Orient Studio and the following query works:
SELECT addTxt("Testuser","foo")
Nodejs/Orientjs: When invoking this function from a nodejs script using Orientjs, it only returns
[ { '#type': 'd', addTxt: '1', '#rid': { cluster: -2, position: 1 } } ]
and the database remains untouched.
I have tried:
//some code
var OrientDB = require('orientjs');
var server = OrientDB({
host: 'localhost',
port: 2424,
});
var db = server.use({
name: 'database',
username: 'admin',
password: 'pass'
db.query('SELECT addTxt(:arg1, :arg2)', {
params: {arg1:"Testuser",arg2:"foo"}
}).then(function (response){
console.log(response);
});
Other queries from Orientjs works.
What am I doing wrong? Is there an other way to invoke a server side function?
You explicit returns "1"
it is right that returns
[ { '#type': 'd', addTxt: '1', '#rid': { cluster: -2, position: 1 } } ]
try to directly explicit the commit in your function
db.commit()

javascript xampp client connection

I try to develop chat application using xampp and jsxc.
when i try to connect with xampp using this http://localhost:5280/http-bind/ url i get this error.
POST http://54.69.166.107:5280/http-bind/
net::ERR_CONNECTION_REFUSEDjsxc.dep.js:4458 sendFunc
I am stuck at this position. This is my function which i written for connection.
$(function() {
jsxc.init({
loginForm: {
form: '#form',
jid: '#username',
pass: '#password'
},
logoutElement: $('#logout'),
rosterAppend: 'body',
root: '/jsxc.example/',
turnCredentialsPath: 'ajax/getturncredentials.json',
loadSettings: function(username, password) {
return {
xmpp: {
url: 'http://localhost:5280/http-bind/',
domain: 'localhost',
resource: 'example',
onlogin: true
}
};
}
});
});
Please suggest me some good ideas for connection. Thanks in advance.

Categories

Resources