denisenkom / go-mssqldb

Microsoft SQL server driver written in go language
BSD 3-Clause "New" or "Revised" License
1.82k stars 501 forks source link

document failorver support #309

Open joaquinicolas opened 7 years ago

joaquinicolas commented 7 years ago

Hi, the driver has support to failover? Thanks!

mikewilliamson commented 7 years ago

Yes, it has support for SQL Server Always On Availability Groups. Just set up the connection with the DNS name of the cluster (which is mapped to multiple IP addresses) and it should work fine.

Fank commented 7 years ago

or setup a failover partner by adding failoverpartner, failoverport to the query:

query := url.Values{}
query.Add("failoverpartner", conf.FailOverHostname)
query.Add("failoverport", fmt.Sprintf("%d", conf.FailOverPort))

u := &url.URL{
    Scheme:   "sqlserver",
    User:     url.UserPassword(conf.Username, conf.Password),
    Host:     fmt.Sprintf("%s:%d", conf.Hostname, conf.Port),
    RawQuery: query.Encode(),
}
db, err := sqlx.Open("sqlserver", u.String())
if err != nil {
    panic(err)
}