looking for an example or code that allows to connect a very simple node.js console application to a SQL Server Instance (2019) using ntlm and no name and password, using tedious and/or mssql.
For tedious, the code below works fine:
but I cannot seem to get the code to use ntlm without providing a name and password.
//
var Connection = require('tedious').Connection;
var config = {
server: '(local)',
authentication: {
type: 'default',
options: {
userName: 'sa',
password: 'your_sa_password' //update me
}
},
options: {
// If you are on Microsoft Azure, you need encryption:
encrypt: true,
database: 'master',
trustServerCertificate: true
}
};
var connection = new Connection(config);
connection.on('connect', function(err) {
// If no error, then good to proceed.
console.log("Connected");
});
connection.connect();
//
(I have tried the above with and without the trustServerCertificate, it seems necessary)
For mssql, I am using the first example on this page:
https://tediousjs.github.io/node-mssql/#connect-callback
And it returns nothing - nothing at all, whether I use sql auth or ntlm. Not sure what is going on there - I have edited the catch block to have an error output, nothing happens.
The Instance is up, the code above runs, I have nothing special or unusual about the SQL Server that I know of at all.
Thoughts? Pointers? Any help deeply appreciated. I
Related
Trying to connect to my database to create a local website but having connection issues.
Running in node.js, this is my server.js file:
let sql = require('mssql');
let config = {
user: 'sa',
password: 'password',
server: '10.0.1.130\\SQLSERVER',
database: 'MY_DB',
};
function connect() {
let dbConn = new sql.ConnectionPool(config);
dbConn.connect()
}
connect();
Upon running this I get the following error:
ConnectionError: Failed to connect to 10.0.1.130:undefined - self signed certificate
code: 'ESOCKET'
Not sure why it is removing \SQLSERVER but that seems to be my issue.
I know the credentials are all correct as I connect to this on another computer (ubuntu) but its being removed and we want to move it to windows, have not been able to connect to this point.
Any suggestions are appreciated.
I have both sequelize and knex in my project (node.js, express, using TypeScript). Just introduced knex as I don't like sequelize and just want a light-weight query builder.
In non-test environments both sequelize and knex work fine, however when running tests (using jest) knex is, apparently, not able to connect to the database. They both use the same databaseUrl, though sequelize has a few more options configured. When running my tests under jest I can't figure out why I am getting
Error: Unable to acquire a connection\n at
Client_PG.acquireConnection
When NODE_ENV is set to 'test', the express app uses a postgres database on my local machine.
Here is the configuration code
const _sqlz = new Sequelize(
config.dbConString,
{
logging: config.nodeEnv === 'test' ? false : false,
define: { freezeTableName: true },
dialect: 'postgres',
...config.sslDB === 'true'
? {
dialectOptions: {
ssl: {
require: true,
rejectUnauthorized: false
}
}
}
: {}
}
);
const knexConfig = {
client: 'postgres',
connection: config.dbConString,
pool: {
min: 0,
max: 15
}
};
const _knex = knex(knexConfig)
When running jest it will give me a Unable to acquire a connection when trying to execute a simple knex query like so
await _knex('myTable').select('*');
To figure out what's happening I configured things such that jest would use the same test database when I set my node environment to be development, i.e. NODE_ENV=development. Interestingly now that development and test point to the same local database, if I run jest, it still gives me the same error about not being able to acquire a connection. So me setting NODE_ENV=test in of itself is not the issue. If I run the app (npm run start) while pointing to my local database, knex works fine, which leads me to think something about jest + knex isn't meshing well. jest + sequelize is working fine.
I tried playing around with the SSL settings but to no avail (I did see some knex + heroku blog posts needing ssl to be explicitly set), e.g.:
const knexConfig = {
client: 'pg',
connection: {
connectionString: config.databaseUrl,
ssl: {
require: true,
rejectUnauthorized: false
}
},
pool: {
min: 0,
max: 15
}
};
Hoping someone with more experience might have some ideas.
Thanks
I am keen on using PouchDB in browser memory for an Angular application. This PouchDB will replicate from a remote LevelDB database that is fed key-value pairs from an algorithm. So, on the remote end, I would install PouchDB-Server. On the local end, I would do the following (as described here) on a node prompt.
var localDB = new PouchDB('mylocaldb')
var remoteDB = new PouchDB('https://remote-ip-address:5984/myremotedb')
localDB.sync(remoteDB, {
live: true
}).on('change', function (change) {
// yo, something changed!
}).on('error', function (err) {
// yo, we got an error! (maybe the user went offline?)
});
How do we start a PouchDB instance that supports TLS for live replication as described in the snippet above?
How do I start a PouchDB instance that supports TLS for live replication?
So after some more searching, it is clear from this topic, HTTPS is not supported for PocuhDB-Server.
Sorry, I misunderstood your question. I thought you intend to connect to a CouchDB server with PouchDB through HTTPS. Therefore, the following answer actually doesn't answer your question.
I created a server.js file like below to communicate with my CouchDB through HTTPS. Please note that the SSL certificate is (in my case) self-signed, and also CouchDB listens by default on port 6984 in the case of TLS:
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"; // Ignore rejection, becasue CouchDB SSL certificate is self-signed
//import PouchDB from 'pouchdb'
const PouchDB = require('pouchdb')
const db = new PouchDB('https://admin:****#192.168.1.106:6984/reproduce')
db.allDocs({
include_docs: true,
attachments: false
}).then(function (result) {
// handle result
console.log(result)
}).catch(function (err) {
console.log(err);
});
I'm running the above file with $ node server.js and I'm getting the expected results:
$ node server.js
{ total_rows: 3,
offset: 0,
rows:
[ { id: '5d6590d3-41c7-4011-be5d-b21f80079ae5',
key: '5d6590d3-41c7-4011-be5d-b21f80079ae5',
value: [Object],
doc: [Object] },
{ id: 'ec6a36d1-952e-4d86-9865-3587c6079fb5',
key: 'ec6a36d1-952e-4d86-9865-3587c6079fb5',
value: [Object],
doc: [Object] },
{ id: 'f508e7aa-b4dc-42fc-96be-b7c1ffa54172',
key: 'f508e7aa-b4dc-42fc-96be-b7c1ffa54172',
value: [Object],
doc: [Object] } ] }
I created the above code with NodeJS on server-side. However, if you want to communicate with CouchDB through HTTPS inside the browser, i.e. on client-side, you have to enable CORS on CouchDB.
I'm new to node.js and I'm trying to connect to a intersystems-cache database. Here is what I have, based off the sample code in the docs:
var sql = require('mssql');
console.log("Connecting...");
sql.connect("mssql://username:password#server:1234/DB").then(function(){
console.log("connected");
}).catch(function(err) {
console.log(err)
});
If I put in the wrong server or port, I get a Failed to connect error, but no matter what else I enter incorrectly (username, pass, db) I get zero output. More importantly, when all the data is correct I never get the connected output.
Is this a compatibility issue with Cache and the mssql library? Or am I doing something wrong?
why do you use mssql, instead of cache, while you have to connect to cache.
If you look at the documentation, you may find and example
var globals = require('cache');
var mydata = new globals.Cache();
mydata.open(
{ path:"/cache20102/mgr",
username: "_SYSTEM",
password: "SYS",
namespace: "USER"
},
function(error, result){}
);
I'm using redisStore in express.
User session data is available at something like sess:eI6Jnj0gzMkdEvszUciqbcJ9, if i do:-
redisClient.set('sess:eI6Jnj0gzMkdEvszUciqbcJ9', 'something', function(err){
console.log(err || ' session changed');
});
'session changed' actually prints on console. but sess:eI6Jnj0gzMkdEvszUciqbcJ9 is not updated in database. I'm presuming, express does not permit redisClient.set to change the session data. How may i achieve it?
PS. The change works on my localhost but does not work, once i use redistogo on heroku.
Edit:-
I check the key not updating, by runnign get 'sess:eI6Jnj0gzMkdEvszUciqbcJ9' command on the console. i am using redis.createClient
var redisClient = require('redis').createClient( 3374, 'birdeye.redistogo.com', {detect_buffers: true});
redisClient.auth('052cb8c4142g202f7878588dd5fb129', function() {
console.log('Redis client connected');
});
I am only guessing that express.js may be 'updating its session automatically Probably, it simply overwrites all your changes with req.session.'