{"record":{"id":"38b0fbc4d163109a","repo":"googleapis/mcp-toolbox","slug":"unable-to-connect-successfully-w-38b0fb","errorCode":null,"errorMessage":"unable to connect successfully: %w","messagePattern":"unable to connect successfully: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"internal/sources/cloudsqlmssql/cloud_sql_mssql.go","lineNumber":80,"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 Cloud SQL MSSQL source\n\tdb, err := initCloudSQLMssqlConnection(ctx, tracer, r.Name, r.Project, r.Region, r.Instance, r.IPType.String(), r.User, r.Password, r.Database)\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":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/sources/cloudsqlmssql/cloud_sql_mssql.go#L62-L98","documentation":"This error is returned by the cloud-sql-mssql source's Initialize when the newly opened Cloud SQL SQL Server connection pool fails its initial health check (db.PingContext). It wraps the underlying driver error, so the real cause (network, auth, instance) is in the wrapped message. The pool is closed before returning, so no leaked connections remain.","triggerScenarios":"Config.Initialize for a source of type 'cloud-sql-mssql' calls db.PingContext(ctx) and the ping fails — e.g. wrong project/region/instance coordinates, invalid ipType (private IP from a non-VPC network), bad user/password, unreachable instance, or the Cloud SQL Admin API not enabled.","commonSituations":"Typos in the instance connection name (project:region:instance), instance stopped or deleted, using ipType: private without running inside the same VPC, wrong SQL Server credentials, missing IAM/ADC permissions when connecting from Cloud Run/GKE, firewall or authorized-networks blocking egress.","solutions":["Verify project, region, and instance values in the toolbox YAML match the Cloud SQL instance exactly","Check the instance is RUNNING in the Cloud SQL console and the Cloud SQL Admin API is enabled","If ipType is private, run the toolbox inside the same VPC (or switch to public)","Confirm user/password are correct by connecting with sqlcmd or another client","Inspect the wrapped error (%w) for the driver-level cause (timeout, auth, DNS)"],"exampleFix":"// before\nkind: Source\nname: my-mssql\ntype: cloud-sql-mssql\nproject: my-proj\nregion: us-central1\ninstance: wrong-instance-name\n// after\nkind: Source\nname: my-mssql\ntype: cloud-sql-mssql\nproject: my-proj\nregion: us-central1\ninstance: my-instance  # exact instance name from `gcloud sql instances list`","handlingStrategy":"try-catch","validationCode":"gcloud sql instances describe INSTANCE_NAME --project=PROJECT --format='value(state,region)'","typeGuard":null,"tryCatchPattern":"src, err := cfg.Initialize(ctx, tracer)\nif err != nil {\n    var pingErr error\n    if errors.Unwrap(err) != nil {\n        pingErr = errors.Unwrap(err)\n    }\n    log.Fatalf(\"cloud-sql-mssql source failed to connect: %v (cause: %v)\", err, pingErr)\n}","preventionTips":["Validate project/region/instance names against `gcloud sql instances list` before starting the toolbox","Match ipType to your network: use public unless running inside the instance's VPC","Test credentials with sqlcmd using the exact same user/password before configuring","Enable the Cloud SQL Admin API and grant the service account cloudsql.client role"],"tags":["cloudsql","mssql","database","connection","startup"],"backgroundTag":"cloud-sql-connection-failure","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"}