tediousjs / node-mssql

Microsoft SQL Server client for Node.js
https://tediousjs.github.io/node-mssql
MIT License
2.23k stars 467 forks source link

ConnectionError: Connection lost - Unable to process incoming packet #1452

Closed Hellome1 closed 1 year ago

Hellome1 commented 1 year ago

Expected behaviour:

ConnectionError: Connection lost - Unable to process incoming packet
    at D:\123\node\node_modules\mssql\lib\tedious\connection-pool.js:70:17
    at Connection.onError (D:\123\node\node_modules\tedious\lib\connection.js:1017:9)
    at Object.onceWrapper (node:events:652:26)
    at Connection.emit (node:events:549:35)
    at Connection.emit (D:\123\node\node_modules\tedious\lib\connection.js:1040:18)
    at Connection.socketError (D:\123\node\node_modules\tedious\lib\connection.js:1399:12)
    at D:\123\node\node_modules\tedious\lib\connection.js:2374:23
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  code: 'ESOCKET',
  originalError: ConnectionError: Connection lost - Unable to process incoming packet
      at Connection.socketError (D:\123\node\node_modules\tedious\lib\connection.js:1399:26)
      at D:\123\node\node_modules\tedious\lib\connection.js:2374:23
      at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
    code: 'ESOCKET',
    isTransient: undefined
  }
}

Actual behaviour:

Configuration:

// paste relevant config here
const sql = require('mssql');

const sqlConfig = {
    user: 'root',
    password: 'sql123',
    database: 'webs',
    server: 'localhost',
    port: 3306,
    pool: {
      max: 10,
      min: 0,
      idleTimeoutMillis: 30000
    },
    options: {
      encrypt: true, // for azure
      trustServerCertificate: false // change to true for local dev / self-signed certs
    }
};

const a = async () => {
    try {
        // make sure that any items are correctly URL encoded in the connection string
        await sql.connect(sqlConfig)
        const result = await sql.query`select * from mytable where id = 1`
        console.dir(result)
    } catch (err) {
        // ... error checks
        console.error(err)
    }
}

a()

module.exports = a

Software versions

dhensby commented 1 year ago

Seems like you're unable to connect. It also doesn't look like you're connecting to azure but you're using encrypt: true - have you tried encrypt: false?

Hellome1 commented 1 year ago

Just tried, still doesn't work.Either encrypt: false, trustServerCertificate: true or encrypt: false, trustServerCertificate: false nor encrypt: true, trustServerCertificate: true or encrypt: true, trustServerCertificate: true doesn't work.

Hellome1 commented 1 year ago

Always the same exception ConnectionError: Connection lost - Unable to process incoming packet.

dhensby commented 1 year ago

Can you connect to the database using other software?

Hellome1 commented 1 year ago

Yeah, It works with 'mysql2'.

dhensby commented 1 year ago

This package is for connecting to SQL server, not MySQL, they are different DBMSs.

I'm afraid this is expected behaviour when trying to connect to a non-SQL Server resource.

Hellome1 commented 1 year ago

Oh I see, thank you for your patience in answering my questions.