2
I have an API that I used with Mysql, but I had to switch to SQL Server. Unfortunately I never used SQL Server, I do not know if you need to download something to get. The API was made in JS. The sequelize configuration of my API with MYSQL was like this:
const Sequelize = require('sequelize');
const config = {
user: "root",
database: "api",
password: "",
host: "localhost",
port: 3306,
dialect: 'mysql',
max: 10000,
idleTimeoutMillis: 3000
};
const seq = new Sequelize(
config.database,
config.user,
config.password,
{
host:config.host,
dialect:config.dialect,
port:config.port,
logging: false,
pool: {
max: config.max,
min: 0,
idle: config.idleTimeoutMillis
}
}
);
module.exports = seq
I made the following change to test with sql server:
const Sequelize = require('sequelize');
const config = {
user: "sa",
database: "dbPortal",
password: "",
host: "localhost",
port: 1433,
dialect: 'mssql',
max: 10000,
idleTimeoutMillis: 3000
};
const seq = new Sequelize(
config.database,
config.user,
config.password,
{
host:config.host,
dialect:config.dialect,
port:config.port,
logging: false,
pool: {
max: config.max,
min: 0,
idle: config.idleTimeoutMillis
}
}
);
module.exports = seq
When I turn on the API it says it was connected, but right away it says it wasn’t. When I test her, she is POST, keeps giving some errors in red at the prompt.
Does anyone know how to configure it to work on SQL Server?
You should fix this part:
host: "localhost"
, should be something likehost: "localhost\sqlexpress"
orhost: "localhost\sql(sua versao)"
– HudsonPH
Mine is SQL server management studio, so it would host:
"localhost\sqlmanagementstudio"
?– Maria
when you open your sql management which path to
Serve Name
this must be your localhost pattern– HudsonPH
No Maria, SQL Server Management Studio is only the program used to interact with an instance of SQL Server, the instance of SQL Server may be running without the need of Management Studio, but you need Management Studio to view its bases, and its tables, etc. I think @Hudsonph was referring to the instance name. When you enter Management Studio, in Object Explorer, if you right-click on the first item and go to Properties you can see the instance name (General > Name).
– Pedro Gaspar
But I think what you will need is an additional property for the Call Sequelize
dialectOptions
, see this article: http://raathigesh.com/Connecting-To-MSSQ-with-Sequelize/– Pedro Gaspar
I did, but when I test the API it gives the following error at the prompt:
Unhandled rejection SequelizeHostNotFoundError: Failed to connect to MSSQLSERVERMARIA:1433 - getaddrinfo ENOTFOUND MSSQLSERVERMARIA ...
– Maria
Placed
MSSQLSERVERMARIA
right on the propertyhost
or on the propertydialectOptions
?– Pedro Gaspar
placed :
dialectOptions: {
 instanceName: 'MSSQLSERVERMARIA'
 }
inhost
I think I’m putting it wrong– Maria
And, as @Hudsonph said, when you open Management Studio the value that appears in
Server name
islocalhost\MSSQLSERVERMARIA
?– Pedro Gaspar
no, it’s:
GUI000123\MSSQLSERVERMARIA
– Maria
then it is not localhost and only
GUI000123\MSSQLSERVERMARIA
– HudsonPH
test with
host: "GUI000123\MSSQLSERVERMARIA"
– HudsonPH
That,
localhost
means the instance is in the machine itself,GUI000123
seems to be another machine on the network, so apparently SQL Server is running on another machine and not the one you are using (localhost).– Pedro Gaspar
I did that, but when I test the API on Postman it loads nothing and at the prompt the error
Unhandled rejection SequelizeHostNotFoundError: Failed to connect to GUI000123MSSQLSERVERMARIA:1433 - getaddrinfo ENOTFOUND GUI000123MSSQLSERVERMARIA ....
– Maria
So try to do as it was in the article:
host: 'GUI000123', dialectOptions: { instanceName: 'MSSQLSERVERMARIA' }
, apparently he doesn’t accept the host+instance name in the fieldhost
.– Pedro Gaspar
That way it doesn’t work either
– Maria
Apparently keeps making mistake of
host
– Maria
What is the exact error?
– Pedro Gaspar
of that mistake:
Unhandled rejection SequelizeConnectionError: Failed to connect to GUI000624:1433 - Could not connect (sequence)
 at Connection.connection.on.err (C:\Users\Administrador\Documents\APIGuido-master\node_modules\sequelize\lib\dialects\mssql\connection-manager.js:99:22)
 at emitOne (events.js:116:13)
 at Connection.emit (events.js:211:7)
 at Connection.socketError (C:\Users\Administrador\Documents\APIGuido-master\node_modules\tedious\lib\connection.js:875:14)
 at C:\Users\Administrador\Documents\APIGuido-master\node_modules\tedious\lib\connection.js:740:25
– Maria
at SequentialConnectionStrategy.connect (C:\Users\Administrador\Documents\APIGuido-master\node_modules\tedious\lib\connector.js:153:9)
 at Socket.onError (C:\Users\Administrador\Documents\APIGuido-master\node_modules\tedious\lib\connector.js:169:16)
 at emitOne (events.js:116:13)
 at Socket.emit (events.js:211:7)
 at emitErrorNT (internal/streams/destroy.js:64:8)
 at _combinedTickCallback (internal/process/next_tick.js:138:11)
 at process._tickCallback (internal/process/next_tick.js:180:9)
– Maria