简体   繁体   English

无法通过nodejs连接到我的ms-sql服务器

[英]Can not connect to my ms-sql server through nodejs

I recently transferred a project to my desktop over from my laptop, and am trying to get the sql server set up. 我最近从我的笔记本电脑转移了一个项目到我的桌面,我正在尝试设置sql server。 I'm testing out the server to make sure it works, and have set up a test table in my sql database. 我正在测试服务器以确保它正常工作,并在我的sql数据库中设置了一个测试表。 Whenever I try to input data into the table I get the following error: 每当我尝试将数据输入表中时,我都会收到以下错误:

UnhandledPromiseRejectionWarning: ConnectionError: Connection is closed. UnhandledPromiseRejectionWarning:ConnectionError:连接已关闭。

I'm able to log into the server using the credentials outlined in the code below through SSMS. 我可以通过SSMS使用下面代码中列出的凭据登录服务器。 Here is the code I am using: 这是我正在使用的代码:

const express = require('express');
var sql = require('mssql');
const app = express();

var config = {
    user: 'djaenike',
    password: 'password',
    server: 'JAENIKE_DESKTOP', 
    database: 'master'
};

app.post('/testing', (req, res) => {
  console.log('request made')
  res.set('Access-Control-Allow-Origin', '*');
    let connection = new sql.ConnectionPool(config, function(err) {
      let request = new sql.Request(connection);
      request.query("insert into testTable (test) values ('a test')");
    })
    res.send(req.query);
    sql.close();
});

const port = process.env.PORT || 5000; //get the process port
app.listen(port, () => console.log(`Server running on port ${port}`));

I'm using postman to make a request to http://localhost:5000/testing and am getting the "request made" in my console window, just can't seem to establish a connection. 我正在使用邮递员向http:// localhost:5000 / testing发出请求,并在我的控制台窗口中收到“请求”,似乎无法建立连接。 Any advice on how to troubleshoot? 有关如何排除故障的任何建议?

Thanks! 谢谢!

Resolved - had to enable TCP/IP protocol in the network configurator. 已解决 - 必须在网络配置器中启用TCP / IP协议。 All set 可以了,好了

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM