I want to make a new connection with the sql server on localhost so that I can able to get the data from the sql server. but there is some problem while doing connection.
error :- [mysql] 2019/02/11 15:30:00 driver.go:81: net.Error from Dial()': dial tcp serverPort:3306: connect: connection timed out
And the code I'm using is
func ConnectMsqlDb() (db *sql.DB, err error) {
db, err = sql.Open("mysql",
fmt.Sprintf("%s:%s@tcp(%s:"+SqlDbPort+")/"+SqlDatabase,
SqlUsername, SqlPassword, SqlServerPort))
fmt.Println("OPEN", db, err)
if err != nil {
return nil, err
}
//defer db.Close()
fmt.Println("PING:-", err)
err = db.Ping()
fmt.Println("PING:-", err)
if err != nil {
return nil, err
}
return db, nil
}
Can you help me to get out from this problem?