Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ConnectionError: Failed to connect to {{host}}:1433 - Cannot call write after a stream was destroyed #931

Closed
bj9215 opened this issue Jul 29, 2019 · 14 comments
Labels
Idle Waiting for more information for a while...

Comments

@bj9215
Copy link

bj9215 commented Jul 29, 2019

Error while connecting to Database (Sql Server 2008 R2)

I am using "mssql": "^5.1.0"

I am able to connect to localhost and SQL Server 2017

[Nest] 29632 - 07/29/2019, 9:34 PM [TypeOrmModule] Unable to connect to the database. Retrying (1)... +876ms
ConnectionError: Failed to connect to {{host}}:1433 - Cannot call write after a stream was destroyed
at Connection. (\nrwl\node_modules\mssql\lib\tedious.js:244:17)
at Object.onceWrapper (events.js:288:20)
at Connection.emit (events.js:200:13)
at Connection.socketError (\nrwl\node_modules\tedious\lib\connection.js:1098:12)
at Socket. (\nrwl\node_modules\tedious\lib\connection.js:971:14)
at Socket.emit (events.js:205:15)
at errorOrDestroy (internal/streams/destroy.js:107:12)
at onwriteError (_stream_writable.js:432:5)
at onwrite (_stream_writable.js:459:5)
at doWrite (_stream_writable.js:413:11)

Kindly suggest some solution :)

@IanChokS
Copy link
Member

Hi @bj9215,

What version of tedious are you using? Mssql package.json is using an outdated version of tedious (current tedious version is v6.2.0). Try updating that and see if it helps? :)

@arthurschreiber
Copy link
Collaborator

Which version of Node.js are you running on? Do you have encryption enabled?

As you're trying to connect to an older version of SQL Server, you most likely need to tweak the encryption settings to use an older version of TLS and use a ciphersuite that is supported on both SQL Server 2008 and the Node.js version you are using.

@IanChokS
Copy link
Member

@bj9215 Are you still having this issue?

@IanChokS IanChokS added the Idle Waiting for more information for a while... label Dec 13, 2019
@crazyx13th
Copy link

crazyx13th commented Dec 18, 2019

I have a similar proplem wit "tedious": "6.6.2",

const config = {
	server: 'local-sql-host',
	authentication: {
		type: 'default',
		options: {
			userName: process.env.AUTH_LOCAL_USR,
			password: process.env.AUTH_LOCAL_PWD,
		},
	},
	options: {
		database: 'DATABASE_NAME',
		encrypted: false,
	},
}
debug connected to {local-sql-host}:1433
debug State change: Connecting -> SentPrelogin
debug State change: SentPrelogin -> SentTLSSSLNegotiation
debug Failed to connect to {local-sql-host}:1433 - Cannot call write after a stream was destroyed
connect $db> test.(): ConnectionError: Failed to connect to {local-sql-host}:1433 - Cannot call write after a stream was de
stroyed
    at ConnectionError (C:\workspace\api-v3\dist\webpack:\node_modules\tedious\lib\errors.js:13:1)
    at Connection.socketError (C:\workspace\api-v3\dist\webpack:\node_modules\tedious\lib\connection.js:1258:1)
    at Socket.<anonymous> (C:\workspace\api-v3\dist\webpack:\node_modules\tedious\lib\connection.js:1093:1)
    at Socket.emit (events.js:215:7)
    at errorOrDestroy (internal/streams/destroy.js:108:12)
    at onwriteError (_stream_writable.js:446:5)
    at onwrite (_stream_writable.js:473:5)
    at doWrite (_stream_writable.js:427:11)
    at writeOrBuffer (_stream_writable.js:415:5)
    at Socket.Writable.write (_stream_writable.js:305:11) {
  message: 'Failed to connect to {local-sql-host}:1433 - Cannot call write after a stream was destroyed',
  code: 'ESOCKET'
}
debug State change: SentTLSSSLNegotiation -> Final
debug Connection lost - 99404:error:1425F102:SSL routines:ssl_choose_client_version:unsupported protocol:c:\ws\deps\o
penssl\openssl\ssl\statem\statem_lib.c:1929:

ConnectionError: Connection lost - 99404:error:1425F102:SSL routines:ssl_choose_client_version:unsupported protocol:c
:\ws\deps\openssl\openssl\ssl\statem\statem_lib.c:1929:

    at ConnectionError (C:\workspace\api-v3\dist\webpack:\node_modules\tedious\lib\errors.js:13:1)
    at Connection.socketError (C:\workspace\api-v3\dist\webpack:\node_modules\tedious\lib\connection.js:1262:1)
    at Socket.<anonymous> (C:\workspace\api-v3\dist\webpack:\node_modules\tedious\lib\connection.js:1093:1)
    at Socket.emit (events.js:210:5)
    at emitErrorNT (internal/streams/destroy.js:92:8)
    at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)
    at processTicksAndRejections (internal/process/task_queues.js:80:21)
[ERROR] 12:23:11 ConnectionError

@crazyx13th
Copy link

forget it! encrypt, not encrypted

@IanChokS
Copy link
Member

IanChokS commented Feb 5, 2020

@bj9215 Closing for now. Feel free to re-open if you're still having this issue!

@IanChokS IanChokS closed this as completed Feb 5, 2020
@raulcampo213
Copy link

One million of thanks!!

@ataft
Copy link

ataft commented Mar 27, 2020

I ran into the same issue. Looks like node-mssql changed the encrypt default from false to true in this PR:
tediousjs/node-mssql#977

@Discartyptics
Copy link

@ataft's comment helped me solve my issue as well - setting "encrypt" to false fixed my issue.

Apollon77 added a commit to ioBroker/ioBroker.sql that referenced this issue May 3, 2020
…(Sentry IOBROKER-SQL-W)

* (Apollon77) Always set "encrypt" flag, even if false because else might en in default true (see tediousjs/tedious#931)
@ko05
Copy link

ko05 commented Jun 5, 2020

@crazyx13th Thanks, this helped me

@Cyl3el2Cleal2
Copy link

forget it! encrypt, not encrypted

This is what if trying to fix on 1 week.
Error message is very unintelligible.

@leemlwando
Copy link

Which version of Node.js are you running on? Do you have encryption enabled?

As you're trying to connect to an older version of SQL Server, you most likely need to tweak the encryption settings to use an older version of TLS and use a ciphersuite that is supported on both SQL Server 2008 and the Node.js version you are using.

Thanks. This solved the issue. i just added --tls-min-v1.0 flag

@CesarAMM
Copy link

CesarAMM commented Oct 3, 2020

Hola tengo el mismo error y ya trate de hacer lo que han comentado anterior mente y me sigue saliendo el mismo error
ConnectionError: Failed to connect to {host}:1433 - Cannot call write after a stream was destroyed

Esta es mi cadena de conexión.

const config = {
user: 'user',
password: 'password',
server: 'host',
database: 'name-dataBase',
pool:{
max: 230,
min: 0
}
};

@rootguigui
Copy link

I just used this parameter in database connection options, options: { encrypt: false }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Idle Waiting for more information for a while...
Projects
None yet
Development

No branches or pull requests