{"record":{"id":"7db003655c4a1c45","repo":"googleapis/mcp-toolbox","slug":"unable-to-connect-successfully-w-7db003","errorCode":null,"errorMessage":"unable to connect successfully: %w","messagePattern":"unable to connect successfully: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/sources/mssql/mssql.go","lineNumber":78,"sourceCode":"}\n\nfunc (r Config) SourceConfigType() string {\n\t// Returns Cloud SQL MSSQL source type\n\treturn SourceType\n}\n\nfunc (r Config) Initialize(ctx context.Context, tracer trace.Tracer) (sources.Source, error) {\n\t// Initializes a MSSQL source\n\tdb, err := initMssqlConnection(ctx, tracer, r.Name, r.Host, r.Port, r.User, r.Password, r.Database, r.Encrypt)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"unable to create db connection: %w\", err)\n\t}\n\n\t// Verify db connection\n\terr = db.PingContext(ctx)\n\tif err != nil {\n\t\tdb.Close()\n\t\treturn nil, fmt.Errorf(\"unable to connect successfully: %w\", err)\n\t}\n\n\ts := &Source{\n\t\tConfig: r,\n\t\tDb:     db,\n\t}\n\treturn s, nil\n}\n\nvar _ sources.Source = &Source{}\n\ntype Source struct {\n\tConfig\n\tDb *sql.DB\n}\n\nfunc (s *Source) IsReadOnly() bool {\n\treturn false","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/sources/mssql/mssql.go#L60-L96","documentation":"This error is returned by the MSSQL source's `Config.Initialize` when `PingContext` fails after the sql.DB handle was created. It means the client could connect far enough to open but the live round-trip to SQL Server failed — typically network, auth, TLS, or server availability issues. The db handle is closed before returning.","triggerScenarios":"Calling Initialize when the server is unreachable (wrong host/port), credentials are rejected, TLS/Encrypt negotiation fails, firewall blocks port 1433, or the context deadline expires during the ping.","commonSituations":"SQL Server not accepting TCP/IP connections (only shared memory/named pipes); Azure SQL firewall rules denying the client IP; wrong password; Encrypt=true against a server without a trusted certificate; VPN/network not connected.","solutions":["Verify host and port (default 1433) are reachable (telnet/nc test)","Check username/password and that SQL auth (or the right auth mode) is enabled","Review the Encrypt setting — try matching the server's TLS requirements or trust the server certificate","Check firewall rules (Azure SQL / local Windows Firewall) allow the client IP","Unwrap the error to distinguish login failure vs timeout vs TLS handshake"],"exampleFix":"// before (TLS handshake failure)\nencrypt: \"true\"\n// after (dev/test only — trust self-signed certs)\nencrypt: \"disable\"  // or configure trust_server_certificate per driver options","handlingStrategy":"retry","validationCode":"func canReachSqlServer(host string, port int) error {\n    conn, err := net.DialTimeout(\"tcp\", net.JoinHostPort(host, strconv.Itoa(port)), 5*time.Second)\n    if err != nil {\n        return err\n    }\n    return conn.Close()\n}","typeGuard":null,"tryCatchPattern":"src, err := cfg.Initialize(ctx, tracer)\nif err != nil && strings.Contains(err.Error(), \"unable to connect successfully\") {\n    time.Sleep(2 * time.Second) // backoff\n    src, err = cfg.Initialize(ctx, tracer)\n}","preventionTips":["Enable TCP/IP protocol on SQL Server","Allowlist client IPs in firewall/Azure SQL","Set sensible context timeouts","Match Encrypt/TLS config to server certificates"],"tags":["mssql","network","authentication","tls","connection"],"backgroundTag":"connection-refused","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"}