You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I am currently facing a problem with the Ping() method in the SQL package, when using this driver. It seems that Ping() suceeds no matter what.
I have some little test code:
package main
import (
"database/sql""fmt""time"
_ "github.com/denisenkom/go-mssqldb"
)
funcmain() {
connString:=fmt.Sprintf("server=%s;user id=%s;password=%s;port=%d;database=%s;log=1",
"host", "username", "password", 1433, "databasename")
conn, err:=sql.Open("mssql", connString)
iferr!=nil {
panic(err)
}
err=conn.Ping()
iferr!=nil {
fmt.Println("ping and reconnect failed:", err.Error())
return
}
fmt.Println("connection to mssql database server ok")
<-time.After(time.Duration(10) *time.Second)
fmt.Println("pinging again database server...")
err=conn.Ping()
iferr!=nil {
fmt.Println("ping and reconnect failed:", err.Error())
return
}
fmt.Println("connection to mssql database server ok")
}
When I run this code and remove the network cable on my laptop when the waiting is going on <-time.After(time.Duration(10) * time.Second), the second pinging still succeeds with: "connection to mssql database server ok", although the database server is physically not reachable (my wireless adapter is deactivated btw).
I am using Ping() to check wether the database server is still online and to automatically re-connect to it. From the godoc of database/sql it states: "Ping verifies a connection to the database is still alive, establishing a connection if necessary.". My apps crash/throw errors on the first workday each week, because we usually restart our database server on the weekends.
Note: If I run this program with no network connection from the beginning it fails up on the first Ping(). It looks like subsquential Ping() don't report correctly.
Note 2: If using conn.SetConnMaxLifetime(time.Duration(3) * time.Second) in this code, the second Ping() will fail as it should.
The text was updated successfully, but these errors were encountered:
Hi, I am currently facing a problem with the Ping() method in the SQL package, when using this driver. It seems that Ping() suceeds no matter what.
I have some little test code:
When I run this code and remove the network cable on my laptop when the waiting is going on
<-time.After(time.Duration(10) * time.Second)
, the second pinging still succeeds with:"connection to mssql database server ok"
, although the database server is physically not reachable (my wireless adapter is deactivated btw).I am using Ping() to check wether the database server is still online and to automatically re-connect to it. From the godoc of
database/sql
it states:"Ping verifies a connection to the database is still alive, establishing a connection if necessary."
. My apps crash/throw errors on the first workday each week, because we usually restart our database server on the weekends.Note: If I run this program with no network connection from the beginning it fails up on the first Ping(). It looks like subsquential Ping() don't report correctly.
Note 2: If using conn.SetConnMaxLifetime(time.Duration(3) * time.Second) in this code, the second Ping() will fail as it should.
The text was updated successfully, but these errors were encountered: