{"record":{"id":"9d88516d64473faf","repo":"microsoft/aspire","slug":"parent-azuresqldatabaseresource","errorCode":null,"errorMessage":"parent","messagePattern":"parent","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Azure.Sql/AzureSqlDatabaseResource.cs","lineNumber":31,"sourceCode":"/// </summary>\n/// <param name=\"name\">The name of the resource.</param>\n/// <param name=\"databaseName\">The database name.</param>\n/// <param name=\"parent\">The Azure SQL Database (server) parent resource associated with this database.</param>\n/// <ats-summary>A resource that represents an Azure SQL database. This is a child resource of an <ats-see cref=\"!:type:AzureSqlServerResource\" />.</ats-summary>\n[DebuggerDisplay(\"Type = {GetType().Name,nq}, Name = {Name}, Database = {DatabaseName}\")]\n[AspireExport(ExposeProperties = true)]\npublic class AzureSqlDatabaseResource(string name, string databaseName, AzureSqlServerResource parent)\n    : Resource(name), IResourceWithParent<AzureSqlServerResource>, IResourceWithConnectionString\n{\n    /// <summary>\n    /// SKU associated with the free offer\n    /// </summary>\n    internal const string FREE_DB_SKU = \"GP_S_Gen5_2\";\n\n    /// <summary>\n    /// Gets the parent Azure SQL Database (server) resource.\n    /// </summary>\n    public AzureSqlServerResource Parent { get; } = parent ?? throw new ArgumentNullException(nameof(parent));\n\n    /// <summary>\n    /// Gets the connection string expression for the Azure SQL database.\n    /// </summary>\n    public ReferenceExpression ConnectionStringExpression =>\n        ReferenceExpression.Create($\"{Parent};Database={DatabaseName}\");\n\n    /// <summary>\n    /// Gets the database name.\n    /// </summary>\n    public string DatabaseName { get; } = ThrowIfNullOrEmpty(databaseName);\n\n    /// <summary>  \n    /// Gets or Sets the database SKU name  \n    /// </summary>  \n    internal bool UseDefaultAzureSku { get; set; } // Default to false  \n\n    /// <summary>","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Azure.Sql/AzureSqlDatabaseResource.cs#L13-L49","documentation":"AzureSqlDatabaseResource throws ArgumentNullException when the parent AzureSqlServerResource is null. Each database must reference its server so the connection string expression can be composed from the server resource.","triggerScenarios":"Constructing AzureSqlDatabaseResource directly with a null parent server resource instead of via AddDatabase on a server builder.","commonSituations":"Manual construction in custom extensions/tests; passing the result of a failed server lookup (null) as the parent.","solutions":["Pass the AzureSqlServerResource created by AddAzureSql as the parent.","Use server.AddDatabase(...) instead of constructing the resource manually.","Guard the server variable for null before constructing the database resource."],"exampleFix":"// before\nvar db = new AzureSqlDatabaseResource(\"appdb\", \"appdb\", GetServerMaybeNull());\n\n// after\nvar sql = builder.AddAzureSql(\"sql\");\nvar db = sql.AddDatabase(\"appdb\");","handlingStrategy":"validation","validationCode":"if (serverResource is null) throw new InvalidOperationException(\"Create the Azure SQL server before adding databases.\");","typeGuard":"if (serverResource is not null) { var db = new AzureSqlDatabaseResource(name, dbName, serverResource); }","tryCatchPattern":null,"preventionTips":["Use sql.AddDatabase on the server builder rather than manual construction.","Chain calls so the server is always available.","Null-check server lookups before database construction."],"tags":["argument-null","azure-sql","constructor"],"backgroundTag":"null-argument","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T09:17:21.228Z"}