{"record":{"id":"626674bada5a01e9","repo":"googleapis/mcp-toolbox","slug":"sql-open-w-626674","errorCode":null,"errorMessage":"sql.Open: %w","messagePattern":"sql\\.Open: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/sources/mssql/mssql.go","lineNumber":189,"sourceCode":"\t// Create dsn\n\tquery := url.Values{}\n\tquery.Add(\"app name\", userAgent)\n\tquery.Add(\"database\", dbname)\n\tif encrypt != \"\" {\n\t\tquery.Add(\"encrypt\", encrypt)\n\t}\n\n\turl := &url.URL{\n\t\tScheme:   \"sqlserver\",\n\t\tUser:     url.UserPassword(user, pass),\n\t\tHost:     fmt.Sprintf(\"%s:%s\", host, port),\n\t\tRawQuery: query.Encode(),\n\t}\n\n\t// Open database connection\n\tdb, err := sql.Open(\"sqlserver\", url.String())\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"sql.Open: %w\", err)\n\t}\n\treturn db, nil\n}\n","sourceCodeStart":171,"sourceCodeEnd":193,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/sources/mssql/mssql.go#L171-L193","documentation":"This error is returned by `initMssqlConnection` when `sql.Open(\"sqlserver\", url)` fails. With the go-mssqldb driver, sql.Open mostly validates the DSN/URL — so this indicates the connection URL built from the source config is malformed (bad scheme, invalid query parameters, unparseable auth).","triggerScenarios":"Calling Initialize when the assembled sqlserver:// URL is invalid: wrong scheme, invalid query parameter names/values (e.g. bad connection timeout syntax), or characters in user/password that break URL parsing before escaping.","commonSituations":"Hand-edited connection parameters injecting bad values; Encrypt value not matching accepted driver values; special characters in password corrupting the URL; port set to a non-numeric value.","solutions":["Unwrap the error to see the exact DSN parse complaint","Verify the built URL starts with sqlserver:// and has valid query params","URL-encode user and password","Check Encrypt/port values are valid per the go-mssqldb driver"],"exampleFix":"// before\nu := url.URL{Scheme: \"sqlserver\", Host: host} // missing port formatting when host has IPv6\n// after\nu := url.URL{Scheme: \"sqlserver\", Host: net.JoinHostPort(host, strconv.Itoa(port))}","handlingStrategy":"validation","validationCode":"func validateMssqlDsnParams(host string, port int) error {\n    if host == \"\" {\n        return errors.New(\"host is required\")\n    }\n    if port < 1 || port > 65535 {\n        return errors.New(\"port out of range\")\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":"src, err := cfg.Initialize(ctx, tracer)\nif err != nil && strings.Contains(err.Error(), \"sql.Open\") {\n    return fmt.Errorf(\"assembled sqlserver:// DSN is invalid; check config: %w\", err)\n}","preventionTips":["Build DSNs from structured config, not free text","URL-encode credential components","Validate Encrypt/port values against driver docs","Smoke-test connections in dev before deploy"],"tags":["mssql","configuration","dsn","client-init"],"backgroundTag":"invalid-connection-uri","analyzedSha":"8cc6e09de2ad7b8bffc77751799585a1401a48eb","analyzedAt":"2026-09-05T01:10:36.887Z","contentChangedAt":"2026-09-05T01:10:36.887Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}