0

我正在尝试在 Visual Studio Code 和 MS SQL Server Management Studio 18 之间建立连接。我发现许多教程的代码与我几乎只是复制和粘贴的代码相同。

const mysql = require('mysql');

//create connection
const db = mysql.createConnection({
    
     host: 'serverName', 
     user: 'userName',
     password: 'password',
     database: 'dbName',    
     
     
});

//connect to mysql environment
db.connect(err =>{
    if(err){
        console.log(err);
    }else{
        console.log("Connected");
    }
});

db.end();

我已经启动并运行了 3 个 SQL 服务(SQL Server、服务器浏览器、服务器代理),但我无法摆脱这个错误

Error: connect ECONNREFUSED 192.168.0.27:3306
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1146:16)
    --------------------
    at Protocol._enqueue (C:\Users\Administrator\Desktop\SQL Connection\node_modules\mysql\lib\protocol\Protocol.js:144:48)
    at Protocol.handshake (C:\Users\Administrator\Desktop\SQL Connection\node_modules\mysql\lib\protocol\Protocol.js:51:23)
    at Connection.connect (C:\Users\Administrator\Desktop\SQL Connection\node_modules\mysql\lib\Connection.js:116:18)
    at Object.<anonymous> (C:\Users\Administrator\Desktop\SQL Connection\connect.js:19:4)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
    at internal/main/run_main_module.js:17:47 {
  errno: -4078,
  code: 'ECONNREFUSED',
  syscall: 'connect',
  address: '192.168.0.27',
  port: 3306,
  fatal: true
}

我在互联网上到处寻找帮助,但没有找到任何有效的方法。所以有人有什么建议吗??

4

0 回答 0