0

I am trying to create a connection between Visual Studio Code and MS SQL Server Management Studio 18. I have found numerous tutorials that have the same code that I pretty much just copied and pasted.

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();

I have 3 SQL services all up and running (SQL Server, Server Browser, Server Agent) and I have not been able to get rid of this error

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
}

I have looked all over the internet for help but haven't found anything that works. So does anyone have any suggestions??

O. Jones
  • 103,626
  • 17
  • 118
  • 172
  • 2
    MySQL <> Microsoft SQL Server. It seems you are trying to use MySQL APIs and port to access a different DBMS product. – Dan Guzman Sep 22 '21 at 17:11
  • 2
    *"I am trying to create a connection between Visual Studio Code and MS SQL Server Management Studio 18."* Both of these are IDEs, why would you want to do that? – Thom A Sep 22 '21 at 17:45
  • 2
    Please [read this](https://stackoverflow.com/tags/econnrefused/info). I fear your question makes very little sense as written. Your sample code is trying to connect a nodejs program (maybe running inside VSCode) to a MySQL database server. But, the message means no MySQL server is running on the target machine (at 192.168.0.27). If you want to connect to a Microsoft SQL Server database, you need the [mssql](https://www.npmjs.com/package/mssql) package, not the [mysql](https://www.npmjs.com/package/mysql) package. – O. Jones Sep 22 '21 at 18:10

0 Answers0