From bd24ca03bcef8426d219de8231a4a5c3f94372f4 Mon Sep 17 00:00:00 2001 From: Alexey Dudko Date: Thu, 10 Sep 2020 12:30:45 +0300 Subject: [PATCH] added a fix that closes a connection with a transactionthat was failed to resume by server (#606) --- mssql.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/mssql.go b/mssql.go index 25c268ed..773ed870 100644 --- a/mssql.go +++ b/mssql.go @@ -184,13 +184,20 @@ func (c *Conn) checkBadConn(err error) error { panic("driver.ErrBadConn in checkBadConn. This should not happen.") } - switch err.(type) { + switch typedErr := err.(type) { case net.Error: c.connectionGood = false return err case StreamError: c.connectionGood = false return err + case Error: + // The server failed to resume the transaction + // Issue https://github.com/denisenkom/go-mssqldb/issues/606 + if typedErr.Number == 3971 && typedErr.Class == 16 { + c.connectionGood = false + } + return err default: return err }