Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 连接到SQL Server端口的节点未找到错误_Node.js_Tedious - Fatal编程技术网

Node.js 连接到SQL Server端口的节点未找到错误

Node.js 连接到SQL Server端口的节点未找到错误,node.js,tedious,Node.js,Tedious,我正在尝试连接到SQL Server: var sql = require("mssql"); var dbConfig = { server: "LAP12\\INSTANCE1", database: "SampleDb", port: 1433, options: { trustedConnection: true } }; // connect to your database sql.connect(dbConfig, fun

我正在尝试连接到SQL Server:

var sql = require("mssql");

var dbConfig = {
    server: "LAP12\\INSTANCE1",
    database: "SampleDb",
    port: 1433,
    options: {
        trustedConnection: true
    }
};

// connect to your database
sql.connect(dbConfig, 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 SampleTable', function (err, recordset) {

        if (err) console.log(err)

        // send records as a response
        res.send(recordset);

    });
});
但我收到了这个错误:

ConnectionError:在ServerName中找不到INSTANCE1的端口

我试着按照这里的指示去做,但是没有用。TCP已启用

将配置更改为此也没有帮助:

var dbConfig = {
    server: "LAP12",
    port: 1433,
    options: {
        instanceName: 'INSTANCE1',
        database: 'SampleDb',
        trustedConnection: true,
    }
};

好的,我也有同样的问题,我会尽力帮助你。 这是我的配置示例

const config = {
    user: 'sa',
    password: '****',
    server: 'DESKTOP-Q5TO47P',
    database: 'dbname',
    options: {           
        encrypt: false
    }
};
您需要打开SQL Server浏览器。转到“启动”菜单或搜索并查找SQL Server Configuration Manager。快跑!(Im使用2018版)

  • 在左侧选项卡中,单击SQL Server服务
  • 现在,在右侧选项卡中双击SQL Server浏览器
  • 将打开一个窗口,您将看到3个选项卡,转到服务选项卡
  • 将启动模式更改为自动并应用
  • 在SQL Server浏览器上单击鼠标左键,然后单击“重新启动”

  • 返回到右侧选项卡,单击SQL Server网络配置

  • 然后是客户端协议
  • 更改TCP/IP以启用

让我知道它是否工作。

添加此加密后:false,应用程序未显示任何错误,也未响应,它未连接到DB

在我的情况下,“SQL浏览器”无法访问,因为防火墙端口未打开。 我的解决方案是打开端口或将dbConfig更改为(无实例名称,无端口):

该端口仍然关闭到SQL浏览器,通过该更改,我可以连接到我的数据库


我的nodejs包“mssql”

在装有SQL Server 2014的Windows 10上对我有效;感谢您使IPAll=>清除TCP动态端口,设置TCP端口1433对我有效
var dbConfig = {
    server: "LAP12",
    database: "SampleDb",
    options: {
        trustedConnection: true
    }
};