2016-05-13 117 views
0

我使用SQL Server Express的命名實例連接到SQL Server 2012 如果我嘗試使用SSMS它的工作原理與它連接,使用這些參數:的NodeJS使用節點MSSQL不起作用

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

使用節點MSSQL:

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 

它記錄了這個錯誤

{ [ConnectionError: Failed to connect to mit-007:undefined in 15000ms] 
    name: 'ConnectionError', 
    message: 'Failed to connect to mit-007:undefined in 15000ms', 
    code: 'ETIMEOUT' } 

回答

0

我認爲mit-007不是您的網絡地址。

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

+0

這是服務器的主機名,如果我使用PHP連接,但不是來自nodejs,它就可以工作 –

+0

嘗試定義端口。默認是1433. – RaV

+0

https://github.com/patriksimek/node-mssql/issues/155 - 類似的問題,也許它有幫助。 – RaV

0

瀏覽各地後,我的問題解決了,這裏就是我所做的

  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

我不是確保以上每個步驟都是必要的,但它們對我有用

0

在繁瑣的驅動程序邏輯中存在一個缺陷,表明在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: { 
     encrypt: false, 
     instanceName: 'SQLEXPRESS', 
     database: 'www', 
     useColumnNames: false, 
     debug: { 
      packet: true, 
      data: true, 
      payload: true, 
      token: true, 
      log: true 
     } 
    } 
}; 

然而,在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: { 
     port: 1443, 
     encrypt: false, 
     database: 'www', 
     useColumnNames: false, 
     debug: { 
      packet: true, 
      data: true, 
      payload: true, 
      token: true, 
      log: true 
     } 
    } 
}; 

注意的運動設置爲選項並刪除instanceName: 'SQLEXPRESS'選項設置。