M
M
Magnus Keef2018-12-07 17:21:40
JavaScript
Magnus Keef, 2018-12-07 17:21:40

How to connect a SQL server database to a node js application?

virtual machine: VMware virtual machine:
win xp with SQL server 2008 installed
physical machine: windows 7 with node.js project

program code
var Connection = require('tedious').Connection;
var Request = require('tedious').Request;

// Create connection to database
var config = {
    database: "TestDb",
    server: "localhost",
    userName: 'TestUser',
    password: '12345678aA',
    //driver: "msnodesqlv14",
    options: {
        encrypt: false
    }
};
var connection = new Connection(config);

connection.on('connect', function (err) {
    if (err) {
        console.log(err);
    }
    else {
        queryDatabase();
    }
}
);

This code works if both the project and the database are on the same machine.
But for my situation, it is necessary to connect the database from the virtual machine.
To do this, you need to correctly register the server address (the picture below, see server: "localhost")
5c0a819d56fa4208312752.png
How to understand what address is needed here? The format of this address?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
Kirill Kudryavtsev, 2018-12-07
@Deissh

You must specify the address of the virtual machine on which the database is running.

A
Abcdefgk, 2018-12-08
@Abcdefgk

Here, as I understand it, there are two questions.
1. And the virtual machine has support for the second adapter (which is not NAT) - "virtual hosting". Patamushta without this, she can go outside (through NAT, which is always enabled by default), but it is impossible to reach her - from the outside.
2. And in Windows XP, the IP address is manually set (some 192.168.33.10), as well as the subnet mask (some 255.255.255.0)
If this is the case, then this 192.168. (instead of the word localhost).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question