使用node-mssql连接到sql server的NodeJS不起作用

时间:2016-05-13 08:24:47

标签: sql-server node.js node-mssql

我使用SQL Server Express 2012的命名实例 如果我尝试使用SSMS连接到它,它可以使用以下参数:

window.setTimeout(getData(), 60000)

使用node-mssql:

Server name: mit-007\SQLEXPRESS2012
Authentication: SQL Server Authentication
    Login: sa
    Password: mit

记录此错误

var sql = require('mssql');
var config = {
    user: 'sa',
    password: 'mit',
    server: 'mit-007',
    driver: 'tedious',
    database: 'Delvi',
    options: {
        instanceName: 'SQLEXPRESS2012'
    }
};

sql.connect(config).then(function(){ // and so on

3 个答案:

答案 0 :(得分:1)

浏览后我解决了问题,这就是我做的事情

  1. 打开SQL Server配置管理器
  2. 单击SQL Server网络配置=> SQLEXPRESS2012的协议
  3. 双击TCP / IP
  4. 更改已启用为是
  5. 点击IP地址
  6. IPAll =>清除TCP动态端口,设置TCP端口1433
  7. 打开services.msc
  8. 启动SQL Server Browser服务
  9. 重新启动SQL Server
  10. 我不确定上述每一步都是必要的,但它们对我有用

答案 1 :(得分:0)

我认为mit-007不是您的网络地址。

https://msdn.microsoft.com/pl-pl/library/ms189921(v=sql.110).aspx

答案 2 :(得分:0)

在繁琐的驱动程序逻辑中存在一个缺陷,表明在mac平台上运行时端口是“未定义的”。

在MS Windows平台上使用以下配置设置时,程序(testtedious.js)运行正常:

var connectionConfig = {
    userName: 'xxx',
    password: 'yyy',
    database: 'zzz',
    server: '127.0.0.1',
    port: 1443,
    debug: true,
    driver: 'tedious',
    options: {
        encrypt: false,
        instanceName: 'SQLEXPRESS',
        database: 'www',
        useColumnNames: false,
        debug: {
            packet: true,
            data: true,
            payload: true,
            token: true,
            log: true
        }
    }
};

但是,在Mac上运行时出现以下错误:

$ node testtedious.js
Tedious-Connection-Pool: filling pool with 2
Tedious-Connection-Pool: creating connection: 1
Tedious-Connection-Pool: creating connection: 2
Tedious-Connection-Pool: connection connected: 1
Tedious-Connection-Pool: connection closing because of error
{ ConnectionError: Failed to connect to 127.0.0.1:undefined in 15000ms
    at ConnectionError (/project-dir/node_modules/tedious/lib/errors.js:12:12)
    at Connection.connectTimeout (/project-dir/node_modules/tedious/lib/connection.js:467:28)
    at ontimeout (timers.js:365:14)
    at tryOnTimeout (timers.js:237:5)
    at Timer.listOnTimeout (timers.js:207:5)
  message: 'Failed to connect to 127.0.0.1:undefined in 15000ms',
  code: 'ETIMEOUT' }
Tedious-Connection-Pool: connection connected: 2
Tedious-Connection-Pool: connection closing because of error
{ ConnectionError: Failed to connect to 127.0.0.1:undefined in 15000ms
    at ConnectionError (/project-dir/node_modules/tedious/lib/errors.js:12:12)
    at Connection.connectTimeout (/project-dir/node_modules/tedious/lib/connection.js:467:28)
    at ontimeout (timers.js:365:14)
    at tryOnTimeout (timers.js:237:5)
    at Timer.listOnTimeout (timers.js:207:5)
  message: 'Failed to connect to 127.0.0.1:undefined in 15000ms',
  code: 'ETIMEOUT' }
Tedious-Connection-Pool: creating connection: 3
Tedious-Connection-Pool: creating connection: 4

这是“修复”:

var connectionConfig = {
    userName: 'xxx',
    password: 'yyy',
    database: 'zzz',
    server: '127.0.0.1',
    port: 1443,
    debug: true,
    driver: 'tedious',
    options: {
        port: 1443,
        encrypt: false,
        database: 'www',
        useColumnNames: false,
        debug: {
            packet: true,
            data: true,
            payload: true,
            token: true,
            log: true
        }
    }
};

请注意port设置移动到选项中以及删除instanceName: 'SQLEXPRESS'选项设置。

相关问题