dsn.go
func GenSQLServer(u *URL) (string, error) {
	host, port, dbname := hostname(u.Host), hostport(u.Host), strings.TrimPrefix(u.Path, "/")

	// add instance name to host if present
	if i := strings.Index(dbname, "/"); i != -1 {
		host = host + `\` + dbname[:i]
		dbname = dbname[i+1:]
	}

	q := u.Query()
	q.Set("Server", host)
	q.Set("Port", port)
	q.Set("Database", dbname)

	// add user/pass
	if u.User != nil {
		q.Set("User ID", u.User.Username())
		pass, _ := u.User.Password()
		q.Set("Password", pass)
	}

	// save host, port, dbname
	if u.hostPortDB == nil {
		u.hostPortDB = []string{host, port, dbname}
	}

	return genOptionsODBC(q, true), nil
}
func GenSQLServer(u *URL) (string, error) {
	host, port, dbname := hostname(u.Host), hostport(u.Host), strings.TrimPrefix(u.Path, "/")

	// add instance name to host if present
	if i := strings.Index(dbname, "/"); i != -1 {
		host = host + `\` + dbname[:i]
		dbname = dbname[i+1:]
	}

	q := u.Query()
	q.Set("Server", host)
	q.Set("Port", port)
	q.Set("Database", dbname)

	// add user/pass
	if u.User != nil {
		q.Set("User ID", u.User.Username())
		pass, _ := u.User.Password()
		q.Set("Password", pass)
	}

	// save host, port, dbname
	if u.hostPortDB == nil {
		u.hostPortDB = []string{host, port, dbname}
	}

	return genOptionsODBC(q, true), nil
}
func GenSQLServer ( u * URL ) ( string , error ) { host , port , dbname := hostname ( u . Host ) , hostport ( u . Host ) , strings . TrimPrefix ( u . Path , " " ) // add instance name to host if present if i := strings . Index ( dbname , " " ) ; i != - 1 { host = host + `\` + dbname [ : i ] dbname = dbname [ i + 1 : ] } q := u . Query ( ) q . Set ( " " , host ) q . Set ( " " , port ) q . Set ( " " , dbname ) // add user/pass if u . User != nil { q . Set ( " " , u . User . Username ( ) ) pass , _ := u . User . Password ( ) q . Set ( " " , pass ) } // save host, port, dbname if u . hostPortDB == nil { u . hostPortDB = [ ] string { host , port , dbname } } return genOptionsODBC ( q , true ) , nil }
// GenSQLServer generates a mssql DSN from the passed URL.
GenSQLServer generates a mssql DSN from the passed URL .