Я изучаю Node.js и написал приведенный ниже код для подключения к базе данных SQL сервера. Моя SQL Серверная установка прошла успешно, и я могу go войти и получить доступ к моей базе данных.
var express = require('express');
var app = express();
app.get('/', function (req, res) {
var sql = require("mssql");
// config for your database
var config = {
user: 'sa',
password: 'testing',
server: 'localhost',
database: 'Education'
};
// connect to your database
sql.connect(config, function (err) {
if (err) console.log(err);
// create Request object
var request = new sql.Request();
// query to the database and get the records
request.query('select * from Student', function (err, recordset) {
if (err) console.log(err)
// send records as a response
res.send(recordset);
});
});
});
var server = app.listen(5000, function () {
console.log('Server is running..');
});
Мне не удалось подключиться к SQL серверу, и я продолжаю получать эту ошибку, которая мне непонятно.
как это исправить? Мой пользователь базы данных и пароль действительны. Есть ли какие-то другие настройки, которые мне нужно сделать, прежде чем я смогу использовать SQL Server?
tedious deprecated The default value for `config.options.enableArithAbort` will change from `false` to `true` in the next major version of `tedious`.
Set the value to `true` or `false` explicitly to silence this message. ..\node_modules\mssql\lib\tedious\connection-pool.js:61:23
ConnectionError: Failed to connect to localhost:1433 - Could not connect (sequence)
at Connection.<anonymous> (C:\Developmentnodesql\node_modules\mssql\lib\tedious\connection-pool.js:68:17)
at Object.onceWrapper (events.js:422:26)
at Connection.emit (events.js:315:20)
at Connection.socketError (C:\Developmentnodesql\node_modules\tedious\lib\connection.js:1290:12)
at C:\Developmentnodesql\node_modules\tedious\lib\connection.js:1116:21
at SequentialConnectionStrategy.connect (C:\Developmentnodesql\node_modules\tedious\lib\connector.js:87:14)
at Socket.onError (C:\Developmentnodesql\node_modules\tedious\lib\connector.js:100:12)
at Socket.emit (events.js:315:20)
at emitErrorNT (internal/streams/destroy.js:92:8)
at emitErrorAndCloseNT (internal/streams/destroy.js:60:3) {
code: 'ESOCKET',
originalError: ConnectionError: Failed to connect to localhost:1433 - Could not connect (sequence)
at ConnectionError (C:\Developmentnodesql\node_modules\tedious\lib\errors.js:13:12)
at Connection.socketError (C:\Developmentnodesql\node_modules\tedious\lib\connection.js:1290:56)
at C:\Developmentnodesql\node_modules\tedious\lib\connection.js:1116:21
at SequentialConnectionStrategy.connect (C:\Developmentnodesql\node_modules\tedious\lib\connector.js:87:14)
at Socket.onError (C:\Developmentnodesql\node_modules\tedious\lib\connector.js:100:12)
at Socket.emit (events.js:315:20)
at emitErrorNT (internal/streams/destroy.js:92:8)
at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)
at processTicksAndRejections (internal/process/task_queues.js:84:21) {
code: 'ESOCKET'
}
}
ConnectionError: Connection is closed.
at Request._query (C:\Developmentnodesql\node_modules\mssql\lib\base\request.js:462:37)
at Request._query (C:\Developmentnodesql\node_modules\mssql\lib\tedious\request.js:346:11)
at Request.query (C:\Developmentnodesql\node_modules\mssql\lib\base\request.js:398:12)
at Immediate.<anonymous> (C:\Developmentnodesql\database\db.js:25:17)
at processImmediate (internal/timers.js:458:21) {
code: 'ECONNCLOSED'
}