简体   繁体   English

从 MS Sql 请求表 - Node.js Web 服务

[英]Requesting tables from MS Sql - Node.js web service

I am in need of assistance in terms of generating a request to my Microsoft SQL Server via a web service (Built in Node.js).我在通过 Web 服务(内置于 Node.js)生成对我的 Microsoft SQL Server 的请求方面需要帮助。

To summarize the problem at hand, it is as follows: I am currently logging into a MS Sql Server Management with a windows auth account - that is all find and dandy however, I am now trying to build a web service that allows for selects and transacts of some tables which is where I am running into issues now specifically in terms of logging in and pulling data to the web service.总结手头的问题如下:我目前正在使用 windows auth 帐户登录到 MS Sql Server Management - 这一切都是 find 和 dandy 但是,我现在正在尝试构建一个允许选择和一些表的交易,这是我现在遇到的问题,特别是在登录和将数据提取到 Web 服务方面。

Code代码

var express = require('express'); var app = express();
app.get('/',function(req,res) {
  const sql = require('mssql');
  // Connection Path
  const myServerPath = String("xxxx\\WS1SQLEXPRESS");
  // Connection String Parameter
  const config = {
      // User Login Details - Windows Auth or General User Account
      user    : 'xxxx-xxx\\AdrianH',
      password: 'xxxxxx',
      // Server path to connect to
      server  : myServerPath,
      // Database
      datebase: 'plex',
      options : {
        trustedConnection: true
      }
  };
  sql.connect(config,function(err) {
    if (err) console.log(err);
    // Create Request Object
    var request = new sql.Request();
    // Query the Database
    request.query('USE plex; SELECT * FROM [plex].[dbo].[tblWorkCenters]',function(err,recordset) {
      if (err) console.log(err)
      // send records as response
      res.send(recordset);
    });
  });
});
// Start Server and listen on //http://localhost:8001/
var server  = app.listen(3213,function(){
  console.log('Server is running...');
});

I have hid sensitive information, here is the error code我隐藏了敏感信息,这是错误代码

{ ConnectionError: Login failed for user ''.
    at Connection.tedious.once.err (C:\Users\adrianh\node_modules\mssql\lib\tedious.js:244:17)
    at Object.onceWrapper (events.js:286:20)
    at Connection.emit (events.js:198:13)
    at Connection.processLogin7Response (C:\Users\adrianh\node_modules\tedious\lib\connection.js:1397:14)
    at Connection.message (C:\Users\adrianh\node_modules\tedious\lib\connection.js:1932:14)
    at Connection.dispatchEvent (C:\Users\adrianh\node_modules\tedious\lib\connection.js:1084:36)
    at MessageIO.messageIo.on (C:\Users\adrianh\node_modules\tedious\lib\connection.js:984:14)
    at MessageIO.emit (events.js:198:13)
    at Message.message.on (C:\Users\adrianh\node_modules\tedious\lib\message-io.js:32:14)
    at Message.emit (events.js:203:15)
  code: 'ELOGIN',
  originalError:
   { ConnectionError: Login failed for user ''.
       at ConnectionError (C:\Users\adrianh\node_modules\tedious\lib\errors.js:13:12)
       at Parser.tokenStreamParser.on.token (C:\Users\adrianh\node_modules\tedious\lib\connection.js:735:29)
       at Parser.emit (events.js:198:13)
       at Parser.parser.on.token (C:\Users\adrianh\node_modules\tedious\lib\token\token-stream-parser.js:27:14)
       at Parser.emit (events.js:198:13)
       at addChunk (C:\Users\adrianh\node_modules\readable-stream\lib\_stream_readable.js:297:12)
       at readableAddChunk (C:\Users\adrianh\node_modules\readable-stream\lib\_stream_readable.js:279:11)
       at Parser.Readable.push (C:\Users\adrianh\node_modules\readable-stream\lib\_stream_readable.js:240:10)
       at Parser.Transform.push (C:\Users\adrianh\node_modules\readable-stream\lib\_stream_transform.js:139:32)
       at doneParsing (C:\Users\adrianh\node_modules\tedious\lib\token\stream-parser.js:80:14) message: 'Login failed for user \'\'.', code: 'ELOGIN' },
  name: 'ConnectionError' }
{ ConnectionError: Connection is closed.
    at Request._query (C:\Users\adrianh\node_modules\mssql\lib\base.js:1399:37)
    at Request._query (C:\Users\adrianh\node_modules\mssql\lib\tedious.js:546:11)
    at Request.query (C:\Users\adrianh\node_modules\mssql\lib\base.js:1335:12)
    at C:\Users\adrianh\Desktop\JEC_Current_Projects\WebService\WCWebServiceIOS.js:30:13
    at _poolCreate.then.catch.err (C:\Users\adrianh\node_modules\mssql\lib\base.js:287:7)
    at process._tickCallback (internal/process/next_tick.js:68:7) code: 'ECONNCLOSED', name: 'ConnectionError' }

** An interesting note to make is in -- ** 一个有趣的笔记是——

(C:\Users\adrianh\node_modules\tedious\lib\token\stream-parser.js:80:14) message: 'Login failed for user \'\'.', code: 'ELOGIN' },
      name: 'ConnectionError' }

It doesn't actually seem to pass my login information - any help will be greatly appreciated thank you.它实际上似乎并没有传递我的登录信息 - 任何帮助将不胜感激,谢谢。

Microsoft SQL 登录屏幕

If you are trying to connect mssql via windows authentication in node JS use this module.如果您尝试通过节点 JS 中的 Windows 身份验证连接 mssql,请使用此模块。

var mssql = require('mssql/msnodesqlv8

Sample:样本:

var mssql = require('mssql/msnodesqlv8')

var dbConfig = {    
    server: 'server',
    driver: 'msnodesqlv8',
    database: 'DBDATA', 
    port: '1433',
    options: {
        trustedConnection: true,              
        debug: {
            packet: false,
            payload: false,
            token: false,
            data: false
        },     
    }
};

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

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