{"record":{"id":"36def0ff01048e15","repo":"googleapis/mcp-toolbox","slug":"unable-to-create-db-connection-w","errorCode":null,"errorMessage":"unable to create db connection: %w","messagePattern":"unable to create db connection: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"internal/sources/cloudsqlmssql/cloud_sql_mssql.go","lineNumber":73,"sourceCode":"\tProject  string         `yaml:\"project\" validate:\"required\"`\n\tRegion   string         `yaml:\"region\" validate:\"required\"`\n\tInstance string         `yaml:\"instance\" validate:\"required\"`\n\tIPType   sources.IPType `yaml:\"ipType\" validate:\"required\"`\n\tUser     string         `yaml:\"user\" validate:\"required\"`\n\tPassword string         `yaml:\"password\" validate:\"required\"`\n\tDatabase string         `yaml:\"database\" validate:\"required\"`\n}\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","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/sources/cloudsqlmssql/cloud_sql_mssql.go#L55-L91","documentation":"This error is thrown from the Cloud SQL MSSQL source's Config.Initialize when initCloudSQLMssqlConnection fails to establish a SQL Server connection via the Cloud SQL Go Connector. It wraps the underlying dial/auth error, meaning the toolbox could not open a database connection for the configured project/region/instance/user.","triggerScenarios":"Config.Initialize is called with a bad project/region/instance combination, wrong IP type, invalid credentials (user/password or IAM auth), unreachable Cloud SQL instance, missing Cloud SQL Admin API permissions for the connector, or the connector failing to fetch an ephemeral certificate.","commonSituations":"Typo in instance or region in the source YAML; instance private-IP only while ipType is public; wrong username/password; service account lacking roles/cloudsql.client; instance stopped; Workload Identity or ADC credentials not present in the environment.","solutions":["Check the wrapped cause: dial tcp errors indicate network/IP-type issues; auth errors indicate bad user/password or IAM credentials","Verify project, region, and instance names in the source config match the actual Cloud SQL instance","Ensure credentials have roles/cloudsql.client and Cloud SQL Admin API is enabled; set GOOGLE_APPLICATION_CREDENTIALS correctly","Match ipType to the instance's connectivity (public vs private) and confirm the instance is RUNNING"],"exampleFix":"// before\nsources:\n  my-mssql:\n    kind: cloud-sql-mssql\n    project: my-prj\n    region: us-centra1\n    instance: my-instance\n// after\nsources:\n  my-mssql:\n    kind: cloud-sql-mssql\n    project: my-prj\n    region: us-central1\n    instance: my-instance","handlingStrategy":"validation","validationCode":"// Preflight before building the source config\nif project == \"\" || region == \"\" || instance == \"\" || user == \"\" || password == \"\" {\n    return errors.New(\"cloud-sql-mssql source requires project, region, instance, user, password\")\n}\n// Verify ADC credentials are available\nif _, err := google.FindDefaultCredentials(ctx, cloudsqlscope...); err != nil {\n    return fmt.Errorf(\"no application default credentials: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"src, err := cfg.Initialize(ctx, tracer)\nif err != nil {\n    var opErr *net.OpError\n    if errors.As(err, &opErr) {\n        log.Printf(\"network failure connecting to Cloud SQL MSSQL: %v\", opErr)\n    }\n    return err // wrapped: \"unable to create db connection: ...\"\n}","preventionTips":["Validate project/region/instance values against `gcloud sql instances describe` before starting the toolbox","Match the ipType setting to the instance's connectivity (private IP requires VPC network access)","Ensure GOOGLE_APPLICATION_CREDENTIALS or Workload Identity provides an account with roles/cloudsql.client","Keep the instance in RUNNABLE state and verify credentials with a direct mssql client test"],"tags":["gcp","cloudsql","mssql","connection","initialization"],"backgroundTag":"database-connection-failed","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"}