HOW TO RESOLVE NODE - SQL Server CONNECTION FAILURE - node.js

I am building a NodeJS app and would like to use SQL Server for persistence storage. Before, I have never had problems connecting to MySQL Server but I am now getting the following error when attempting to connect to SQL Server:
ConnectionError: Error: [Microsoft][SQL Server Native Client 11.0]SQL Server Network Interfaces: Connection string is not valid [87].
Error: [Microsoft][SQL Server Native Client 11.0]Login timeout expired
Error: [Microsoft][SQL Server Native Client 11.0]A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online.
Below is my config and connection using mssql/msnodesqlv8 module.
const mssql = require('mssql/msnodesqlv8')
const dbConfig =
"server":"127.0.0.1",
"user":"sa",
"password":"PasswordHere",
"database":"DBName_Here",
"driver":"msnodesqlv8",
"dialect":"mssql",
"port":1433,
"options":{
"enableArithAort":true,
"instanceName":"MSSQLSERVER"
},
"connectionTimeout":15000,
"pool":{
"max":100,
"min":0,
"idleTimeoutMillis":30000
}
}
ValidateUser = async (data)=>{
console.log(data)
return new Promise(async (resolve, reject)=>{
console.log(dbConfig)
try{
let pool = await mssql.connect(dbConfig)
let results = await pool.request().query(`SELECT * FROM Users WHERE Username = ${data.username} AND Password = ${data.password}`)
results = results.recordSets
console.log(results)
if(results.length > 0){
resolve(results)
}else{
reject('Wrong Username or Password!')
}
}catch(err){
console.log(err)
reject('DB Exception: Authentication failed!')
}
})
}
I have attempted variations of the config including replacing the IP with my machine name DESKTOP-GLPFSS\COMPUTERNAME but to no avail. All relevant support will be greatly appreciated.

Please check the settings in SQL Server Configuration Manager are properly set:
Please follow below steps to verify it and try to configure it as per the attached image
Click the Windows key + R to open the Run window.
Type compmgmt.msc in the Open: box.
Click OK.
Expand Services and Applications.
Expand SQL Server Configuration Manager
Instead of "MSSQLSERVER" look for instance name which you provided at time of installation.

Related

How do i resolve this Mongo Server Selection Error

Am quiet new to backend and database. I have a solution currently using mongodb. It was working fine till yesterday when i starting having the connect ETIMEDOUT 13.37.254.237:27017 error. Nothing was changed in the URI path or tampered with. It just started and i have not been able to sort it out.
is there any help available please?
I have created another cluster and its working well. But my initial cluster that has datas which are live from clients is not connecting still.
My connection code
I have used these connections code but it has not worked. It was connecting fine all through yesterday but today without tampering with the code, couldn't connect to my mongodb
mongoose.connect(process.env.MONGO_URI,{ useNewUrlParser: true, useUnifiedTopology: true });
const connectDB = async () => {
try {
const conn = await mongoose.connect(process.env.MONGO_URL);
console.log(`MongoDB Connected: ${conn.connection.host}`);
} catch (error) {
console.log(error);
process.exit(1);
}
};
my mongoose connection and the timedout error
Whenever you connect to Mongodb using IPs that keep updating from your system causes this kind of issues.
also this can be due to your network connection. So i will advice you to:
To allow connection from any IP address(but must ensure your URI is not made known to the public to avoid attack/ access from unwanted users.)
2.Check your network status(data)
3. Run the mongo URI on your atlas

ConnectionError: Login failed for user '' while window authentication using Nodejs(Nestjs), msnodesqlv8, typeORM

I have to connect with mssql database using window authentication where I am using Nodejs and msnodesqlv8. I followed How to connect to SQL Server with windows authentication from Node.JS using mssql module to do the setup code but as it's window authentication so no username/password required but after writing code
connection using above link
const sql = require("mssql/msnodesqlv8");
const conn = new sql.ConnectionPool({
database: "db_name",
server: "server_name",
driver: "msnodesqlv8",
options: {
trustedConnection: true
}
});
conn.connect().then(() => {
// ... sproc call, error catching, etc
// example: https://github.com/patriksimek/node-mssql#request
});
I am getting this error ConnectionError: Login failed for user '', I tried a lot of links to understand the root cause but I am unable to understand also I am working on Mac M1, Azure data studio where manually I am not able to connect to database using window authentication as I am getting error 'Connection failed due to Kerberos error' so is this the cause, please help me to understand the issue.

Django 1.11 Unable to Connect SQL Server Express 2012 with django-pyodbc-azure

FYI, I am just getting back into programming after not coding for a few years. My programming lingo might be off; so, I hope this does not off-put anyone in the community
Technologies I am using for this issue:
Windows 7 Pro 64-bit
Python 3.5.3
Django 1.11.7
SQL Server Express 2012
django-pyodbc-azure 1.11.0.0
After reading suggestions online on what middleware connection I should use between my Django app and my SQL Server database, people were recommending django-pyodbc-azure with Django 1.11.
This is my python code (settings.py) that is supposed to connect to my database:
DATABASES = {
'default': {
'NAME': 'INVENTORY.mdf',
'ENGINE': 'sql_server.pyodbc',
'USER': 'sqlserveradmin',
'PASSWORD': '****',
'OPTIONS' : {
'driver' : 'SQL Server Native Client 11.0'
},
}
}
I did not include the host and port since I assumed that it would go to localhost:8000. Also, I put the database in the same location as the manage.py file:
mysite/
├──mysite/
| └──settings.py
├──manage.py
└──INVENTORY.mdf
However, I keep getting the below message:
django.db.utils.OperationalError: ('08001', '[08001] [Microsoft][SQL Server
Native Client 11.0]Named Pipes Provider: Could not open a connection to SQL
Server [2]. (2) (SQLDriverConnect); [08001] [Microsoft][SQL Server Native
Client 11.0]Login timeout expired (0); [08001] [Microsoft][SQL Server Native
Client 11.0]Invalid connection string attribute (0); [08001] [Microsoft][SQL
Server Native Client 11.0]A network-related or instance-specific error has
occurred while establishing a connection to SQL Server. Server is not found
or not accessible. Check if instance name is correct and if SQL Server is
configured to allow remote connections. For more information see SQL Server
Books Online. (2)')
I am thinking it has to do with the following:
My database still won't allow the connection
My settings.py code is missing something.
Any help would be greatly appreciated

Can't connect to mongo lab on arduino yun

I can't connect to a database with mongodb or mongoose on nodejs on my arduino yun.
Unable to connect to the mongoDB server. Error: { [MongoError: Authentication failed.]
name: 'MongoError',
message: 'Authentication failed.',
ok: 0,
code: 18,
errmsg: 'Authentication failed.' }
I get that error. The code works fine on my desktop computer.
//lets require/import the mongodb native drivers.
var mongodb = require('mongodb');
//We need to work with "MongoClient" interface in order to connect to a mongodb server.
var MongoClient = mongodb.MongoClient;
// Connection URL. This is where your mongodb server is running.
var url = 'mongodb://*******:********#address:23118/arduino';
// Use connect method to connect to the Server
MongoClient.connect(url, function (err, db) {
if (err) {
console.log('Unable to connect to the mongoDB server. Error:', err);
} else {
//HURRAY!! We are connected. :)
console.log('Connection established to', url);
// do some work here with the database.
//Close connection
db.close();
}
});
I am trying to connect to a mongo lab database. I have not tried connecting to any other database to troubleshoot. This is because I cannot find a free trial version where I do not need a credit card.
EDIT:
I got an Object Rocket instance and it works perfectly on my arduino yun. However it is very expensive; $30 a month (currently on the trial). And I don't need speed or lots of data. So if anyone could figure out why it doesnt work on mlab that would be great.
I've experienced some authentication issues in the past and I've addressed them following the next steps:
1) Identify version numbers of both mongo server and mongoose
2) Identify what authentication mechanism does your server use and make sure that mongoose is trying to authenticate with the one your server is expecting. If you're using an old version, some authentication mechanism might not be supported, so you'd need to upgrade.
3) Identify where the user has been created. Check out Authentication Database and make sure that your client is authenticating using such database. It can be different than the database you store your data. Indeed, it uses to be admin. If so, take a look to the authSource option you can add to your connection string. More info here.
In addition to all of the above, I'd recommend you to use the the mongo client to verify your credentials are right and you can connect to the database.

PostgreSQL not working with Node.js on Heroku

I'm trying to work on a node.js application using Heroku and a PostgreSQL database.
I have followed the tutorial on Heroku documentation:
https://devcenter.heroku.com/articles/nodejs#using-a-postgres-database
Dependencies are good, and my code is basically the following:
var pg = require('pg');
pg.connect(process.env.DATABASE_URL, function(err, client) {
var query = client.query('CREATE TABLE users (id bigint auto_increment not null, login varchar(250), constraint pk_users primary key (id) )');
query.on('row', function(row) {
console.log(JSON.stringify(row));
});
});
I have tried various forms of this query, like this one:
var client = new pg.Client(process.env.DATABASE_URL);
client.connect();
But I got each time this error in my heroku logs:
at Object.afterConnect [as oncomplete] (net.js:875:19)
Error: connect ECONNREFUSED
at errnoException (net.js:884:11)
If someone has already encountered this kind of problem, any help would be welcome.
Thank you.
I would suggest trying a console.log(process.env.DATABASE_URL); and then using that address to manually connect using a client on your local machine. I understand that the Heroku database servers are open for remote connection(but I have been wrong before).
Failing that you can get a heroku console and use the postgre client.
ECONNREFUSED is a socket error that pops up when you try to connect to an address that is not contactable/connectable/listening.
If process.env.DATABASE_URL does return the correct and connectible address then I would be doing console.log(pg); to ensure that object is what I would expect it to be.

Resources