我正在嘗試將節點 js 腳本連接到 MsSQL 資料庫服務器,但失敗了。
然而,我的 Microsoft SQL Server Management 能夠連接到資料庫。
node.js 代碼
var Connection = require('tedious').Connection;
var config = {
server: "172.168.200.35",
dialect: "mssql",
port:51433,
authentication: {
type: 'default',
options: {
userName: 'testuser',
password: 'abc123'
}
},
options: {
database: 'IoTDb'
}
};
var connection = new Connection(config);
// Attempt to connect and execute queries if connection goes through
connection.on("connect", err => {
if (err) {
console.error(err.message);
} else {
executeStatement();
}
});
運行代碼時,我收到此錯誤
Failed to connect to 172.168.200.35:51433:1433 - getaddrinfo ENOTFOUND 172.168.200.35:51433
我不明白為什么它無法連接埠1433,因為埠被定義為51433
但是,當我嘗試通過此登錄資訊連接到資料庫時(與節點配置變數相同)

它連接,我通過資料庫獲得了這個視圖

有關資料庫的資訊,它通過另一臺電腦上的 docker 運行,但可以訪問
我感動port到options現在的錯誤是這樣的
Failed to connect to 172.168.200.35:51433:51433 - getaddrinfo ENOTFOUND 172.168.200.35:51433
uj5u.com熱心網友回復:
由于此問題顯示應在以下位置指定埠options:
var config = {
server: "172.168.200.35",
dialect: "mssql",
...
options: {
database: 'IoTDb',
port:51433,
}
};
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/379324.html
標籤:节点.js sql-server
