# DataBase Connection Custom

**URL:** <https://community.auth0.com/t/database-connection-custom/42361>\
**Category:** Get Help\
**Created:** [May 5, 2020, 12:47pm UTC](https://community.auth0.com/t/database-connection-custom/42361 "2020-05-05T12:47:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![lundzas](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@lundzas](https://community.auth0.com/u/lundzas)\
**Post date:** [May 5, 2020, 12:47pm UTC](https://community.auth0.com/t/database-connection-custom/42361/1 "2020-05-05T12:47:02Z")

</div>

Hello, I want to create a custom database that can save my users. But when im try to do that i get that Failed to connect to localhost,1434:1433 - getaddrinfo ENOTFOUND localhost,1434 localhost,1434:1433"…

function login(email, password, callback) {  
//this example uses the “tedious” library  
//more info here: [http://pekim.github.io/tedious/index.html](http://pekim.github.io/tedious/index.html)  
const bcrypt = require(‘bcrypt’);  
const sqlserver = require(‘tedious@1.11.0’);

const Connection = sqlserver.Connection;  
const Request = sqlserver.Request;  
const TYPES = sqlserver.TYPES;

const connection = new Connection({  
userName: ‘-Have right it here------’,  
password: ‘Have right it here-------’,  
server: ‘localhost,1434’,  
options: {  
database: ‘Have right it here------’  
}  
});

const query = ‘SELECT Id, Nickname, Email, Password FROM dbo.Users WHERE Email = @Email’;

connection.on(‘debug’, function (text) {  
console.log(text);  
}).on(‘errorMessage’, function (text) {  
console.log(JSON.stringify(text, null, 2));  
}).on(‘infoMessage’, function (text) {  
console.log(JSON.stringify(text, null, 2));  
});

connection.on(‘connect’, function (err) {  
if (err) return callback(err);

```
const request = new Request(query, function (err, rowCount, rows) {
  if (err || rowCount < 1) return callback(err || new WrongUsernameOrPasswordError(email));

  bcrypt.compare(password, rows[0][3].value, function (err, isValid) {
    if (err || !isValid) return callback(err || new WrongUsernameOrPasswordError(email));

    callback(null, {
      user_id: rows[0][0].value,
      nickname: rows[0][1].value,
      email: rows[0][2].value
    });
  });
});

request.addParameter('Email', TYPES.VarChar, email);
connection.execSql(request);

```

});  
}

---

<div class="post-metadata">

**Author:** ![john.gateley](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/john.gateley/32/10879_2.png) [@john.gateley](https://community.auth0.com/u/john.gateley)\
**Post date:** [May 5, 2020, 1:55pm UTC](https://community.auth0.com/t/database-connection-custom/42361/2 "2020-05-05T13:55:27Z")

</div>

localhost means the host the script is running on, in this case an Auth0 server.

You need to run your DB on a publicly available IP address.

John

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [May 6, 2020, 12:36pm UTC](https://community.auth0.com/t/database-connection-custom/42361/3 "2020-05-06T12:36:49Z")

</div>

Thanks for sharing that solution John!

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [May 21, 2020, 12:36pm UTC](https://community.auth0.com/t/database-connection-custom/42361/4 "2020-05-21T12:36:50Z")

</div>

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.
