I have the following problem, I have an express project that uses the package mssql
to connect to a SQL Server database. To make the connection I have to specify the data in an object.
produccion = {
user: 'xxx',
password: 'xxx',
server: 'nombre\\nombre',
database: 'xxx'
};
In the case of server
contains a \\
. Although I really don't know why.
I am developing the project on the local network with a Windows machine, I have no problem connecting to the server. Now when I pass it to a Debian server that is also on the local network the connection cannot be established.
I have tried to replace the nombre\\nombre
with the ip, but it doesn't work either on my windows machine or on the debian server.
This is the error it sends me:
{ ConnectionError: Failed to lookup instance on miServidor - getaddrinfo ENOTFOUND miServidor at Connection.tedious.once.err (/var/www/html/node_modules/mssql/lib/tedious.js:239:17) at Object.onceWrapper (events.js:273:13) at Connection.emit (events.js:182:13) at /var/www/html/node_modules/tedious/lib/connection.js:848:20 at /var/www/html/node_modules/tedious/lib/instance-lookup.js:83:15 at GetAddrInfoReqWrap.callback (/var/www/html/node_modules/tedious/lib/sender.js:58:18) at GetAddrInfoReqWrap.onlookupall [as oncomplete] (dns.js:70:17) code: 'EINSTLOOKUP', originalError: { ConnectionError: Failed to lookup instance on miServidor - getaddrinfo ENOTFOUND miServidor at ConnectionError (/var/www/html/node_modules/tedious/lib/errors.js:12:12) at /var/www/html/node_modules/tedious/lib/connection.js:848:36 at /var/www/html/node_modules/tedious/lib/instance-lookup.js:83:15 at GetAddrInfoReqWrap.callback (/var/www/html/node_modules/tedious/lib/sender.js:58:18) at GetAddrInfoReqWrap.onlookupall [as oncomplete] (dns.js:70:17) message: 'Failed to lookup instance on miServidor - getaddrinfo ENOTFOUND miServidor',
code: 'EINSTLOOKUP' },
name: 'ConnectionError' }
The documentation mssql
is not very clear about the EINSTLOOKUP
.
EINSTLOOKUP (ConnectionError) - Instance lookup failed.
You cannot substitute
nombre\nombre
for an IP, since they are not equivalent. I am going to explain to you what the SQL Server client supports in that connection parameter and I think after that you will be able to do it yourself.When you are going to connect to a database, there is a parameter commonly known as server name , server name or simply server , which tells the engine the qualified name of the SQL Server instance to connect to.
In other words, it is not the computer to which it connects, but the instance , which will always reside inside a computer and can be the only instance or the default instance (more on that later).
Let's start by defining the parts a can eventually be composed of:
MiPC
orJuan-Laptop
midominio.com
,basededatos.midominio.com
, etc.127.0.0.1
,192.168.0.41
,190.191.192.193
, etc.(local)
, which always resolves to the team itself.With this in mind, the server name string can take 3 forms:
ServidorBD\SQLExpress
,db.miempresa.com\MainERP
,10.14.17.11\Pruebas
, etc.ServidorBD,1433
,db.miempresa.com,61254
,10.14.17.11,18141
This is the same whether the server is Windows or Linux .
To diagnose the problem, what you should verify, from the computer where you are trying to establish the connection, is that:
The server name can be resolved without problems. You can easily test it, for example, making a
ping
with the name of the server, taking advantage of the fact that this command looksup the name, translates it to an IP address and finally tries to ping . A test on Windows, when it can't resolve the name, returns something like:In linux it is something similar
That you can connect to the SQL server port , either with telnet, with a SQL Server client or with any other program that can establish a TCP connection, for example.