I'm trying to connect my electron app to a database, but I keep getting the same error
ETIMEOUT
or that the user don't have access
But if I try with my local database works fine, any ideas of why is this happening?
var mysql = require('mysql');
// Add the credentials to access your database
var connection = mysql.createConnection({
host : 'xxx.xxx.xxx',
user : 'xxxxx',
password : 'xxxxxxx',
database : 'xxxxx',
pool: {
max: 1000,
min: 0,
idleTimeoutMillis: 30000000
},
options: {
"enableArithAbort": false,
"encrypt": false
},
debug: true
});
// connect to mysql
connection.connect(function(err) {
if(err){
console.log(err.code);
console.log(err.fatal);
} else {
console.log("OK");
}
});
Related
I am trying to connect to MSSQL database via Windows Authentication in Electron Application.
I use packages:
msnodesqlv8 2.1.0
mssql 7.0.0
As a result, when the pool is connected, the following is displayed:
Error occurred in handler for 'SqlQuery': ConnectionError: Failed to connect to : undefined - self signed certificate
My config code:
import { IResult, config } from "mssql";
const connectionSettings: config = {
server: "my_server_name",
port: 1443,
driver: "msnodesqlv8",
options: {
trustedConnection: true,
connectionString: "Data Source=my_server_name;database=my_database;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False"
}
};
My connection code:
import { ConnectionPool, IResult, config } from "mssql";
public SqlQuery(poolOptions: config, query: string)
: Promise<IResult<any>> {
return new Promise((resolve, reject) => {
console.log(poolOptions);
const pool = new ConnectionPool({
...poolOptions
});
pool.connect()
.then(() => {
console.log("CONNECT");
return pool.query(query);
})
.then(values => {
console.log(values);
return resolve(values);
})
.catch(reason => {
reject(reason);
});
});
I also face the same error while connecting with SQL server using nodejs
First you have to install mssql,stream and tedious dependency in your project and then write the following code `
var sql = require("mssql");
var config = {
user: "USER_NAME",
password: "PASSWORD",
server: "Your_SERVER_NAME",
database: "DATABASE_NAME",
port: 1433,
options: {
encrypt: false,
useUTC: true,
},
pool: {
max: 100,
min: 0,
idleTimeoutMillis: 3600000,
connectionTimeout: 3600000,
requestTimeout: 3600000,
},
};
var database = new sql.ConnectionPool(config);
database
.connect()
.then(function () {
console.log("connected");
})
.catch((err) => {
console.log(err);
});`
I am trying to connect the multiple database with the API request. I tried to connect the DB using this code:
const connectionString = `mongodb+srv://${process.env.DB_HOST}/${company.dbName}`;
const client = new MongoClient(connectionString, {
autoReconnect: true,
reconnectTries: 60,
reconnectInterval: 10000,
useNewUrlParser: true,
auth: {
user: process.env.DB_USER,
password: process.env.DB_PASS
}
});
await client.connect();
await client.db(company.dbName);
I didn't achieve any solution with the mentioned code.
Looking for the good solution :)
I am using nodejs-v9.2.0 and mysql in my application.
Error:
code: 'ER_CON_COUNT_ERROR'
errno: 1040
NPM Modules:
Mysql
Mysql wrapper
Code:
var mysql = require('mysql');
var pool = mysql.createPool({
canRetry: true,
database: "dbname",
host: "host",
user: "user",
password: "password",
connectionLimit: 100,
supportBigNumbers: true,
bigNumberStrings: true,
charset: 'utf8mb4_unicode_ci',
multipleStatements: true,
debug: true
waitForConnections: true,
queueLimit: 0
});
pool.on('connection', (connection) => {
connection.on('error', (err) => {
connection.release();
});
connection.on('close', (err) => {
console.error(new Date(), 'MySQL close', err);
});
});
var createMySQLWrap = require('mysql-wrap');
var sql = createMySQLWrap(pool);
Note:
I have noticed an open issue in the mysql npm github.
Any work around to solve this issue?
Any suggestion will be grateful
const sql = require("mssql");
var sqlconfig = {
server:"192.168.200.5",
database:"DATA",
user: "labo",
password: "*********",
connectionTimeout: 30000,
port: 1433,
dialect: "mssql",
dialectOptions: {
"instanceName": "SQLEXPRESS"
},
};
new sql.ConnectionPool(sqlconfig).connect().then(pool => {
console.log(pool); return pool.query('select * from data where id = 2')
}).then(result=> {
console.dir(result)
}).catch(err => {
console.log(err);
})
Problem: Return Login failed for user 'Labo' ELOGIN when trying to login to Microsoft SQL Server using node.js.
What I have tried: Grab the example codes on npm to find the avoid extra problems. Error still persisted.
What I suspect: The username I inserted was "labo" but the one returned from err was 'Labo' (with capitalized 'L'). Is this a bug?
This is my code
I am trying to connect to sql server using node js. I have installed the package mssql and using sublime text editor.
this is my node js code.
var sql = require('mssql');
var dbConfig={
server:'CCI-LPT-21',
userName: 'sa',
password: 'sa123#',
port:1433,
options: {
instanceName: 'MSSQLSERVER2K12',
database: 'HRApp',
debug: {
packet: false,
payload: false,
token: false,
data: false
},
}
};
function getEmp()
{
//console.log(dbConfig);
var conn = new sql.Connection(dbConfig);
var req = new sql.Request(conn);
//console.log(conn)
conn.connect(function(err){
if(err){console.log(err);
return;
}
req.query("select * from Team",function(err,recordset){
if(err){
console.log(err);
return;
}
else
{
console.log(recordset);
}
conn.close();
})
})
}
getEmp();
when I run this from command promt,I get this error
when I did Console.log(dbconfig) it was having this data
Your error it's you have to set user and not userName.
Check this example from the doc:
var config = {
user: '...',
password: '...',
server: 'localhost', // You can use 'localhost\\instance' to connect to named instance
database: '...',
options: {
encrypt: true // Use this if you're on Windows Azure
}
}
It's user and not userName.