{"catalogRevision":"cat_726f873af6f566cc","recipeId":"page:guides:asp-net-core:database-connection","recipeRevision":"r1","canonicalPath":"/guides/asp-net-core/database-connection","label":"Connect Postgres for ASP.NET Core","title":"How to connect an ASP.NET Core app to Postgres on Ample","family":"Framework operation","summary":"Database connection for a ASP.NET Core app on Ample. Verified on ASP.NET Core: a managed PostgreSQL database auto-provisioned and injected as DATABASE_URL, with real queries succeeding at request time (records=ok). Build and start: dotnet publish -c Release -o out in the builder, then dotnet <entry>.dll on the dotnet-10 template with ASPNETCORE_URLS bound to PORT.","representativeQueries":["Connect Postgres for ASP.NET Core","Where can I host Connect Postgres built with ASP.NET Core?","I need driver setup, connection settings, secret handling and a real connection test."],"breadcrumbIds":["discovery","stack","stack:frameworks","stack:framework-asp-net-core","page:guides:asp-net-core:database-connection"],"breadcrumbs":[{"id":"discovery","label":"Agent hosting discovery","canonicalPath":"/discover/discovery","kind":"root"},{"id":"stack","label":"Frameworks and execution targets","canonicalPath":"/discover/stack","kind":"facet"},{"id":"stack:frameworks","label":"Frameworks","canonicalPath":"/discover/stack/frameworks","kind":"group"},{"id":"stack:framework-asp-net-core","label":"ASP.NET Core","canonicalPath":"/discover/stack/framework-asp-net-core","kind":"atom"},{"id":"page:guides:asp-net-core:database-connection","label":"Connect Postgres for ASP.NET Core","canonicalPath":"/guides/asp-net-core/database-connection","kind":"recipe"}],"parentIds":["stack:framework-asp-net-core","intent:connect-app-to-database","pattern:relational-records"],"parents":[{"id":"stack:framework-asp-net-core","label":"ASP.NET Core","canonicalPath":"/discover/stack/framework-asp-net-core","kind":"atom"},{"id":"intent:connect-app-to-database","label":"Connect app to database","canonicalPath":"/discover/intent/connect-app-to-database","kind":"atom"},{"id":"pattern:relational-records","label":"Relational records","canonicalPath":"/discover/pattern/relational-records","kind":"atom"}],"resourceRequirements":["primitive:compute","primitive:postgres"],"infrastructureRequirements":[{"primitiveId":"primitive:compute","label":"Compute","canonicalPath":"/discover/primitive/compute","status":"verified","summary":"Apps run in isolated x86_64 Firecracker microVMs; sizes are the priced VM sizes."},{"primitiveId":"primitive:postgres","label":"Postgres","canonicalPath":"/discover/primitive/postgres","status":"verified","summary":"Managed PostgreSQL 16 with pgvector runs in its own microVM and is auto-provisioned when an app needs a database and no DATABASE_URL is supplied."}],"framework":"ASP.NET Core","workload":"Connect Postgres","releaseStatus":"published","supportStatus":"verified","executionStatus":"ready","docsOnly":false,"prerequisites":["An ASP.NET Core project (dotnet publish -c Release -o out in the builder, then dotnet <entry>.dll on the dotnet-10 template with ASPNETCORE_URLS bound to PORT)","A PostgreSQL driver reading DATABASE_URL at runtime","An Ample account token with servers:write, databases:read"],"testedConfiguration":{"template":"dotnet-10","runtime":"dotnet","size":"s-1vcpu-1gb","build":"dotnet publish -c Release -o out","start":"ASPNETCORE_URLS=http://0.0.0.0:$PORT dotnet out/$(basename $(ls out/*.runtimeconfig.json | head -n 1) .runtimeconfig.json).dll"},"inputSchema":{"additionalProperties":false,"properties":{"env":{"description":"Encrypted environment variables","items":{"pattern":"^[A-Z][A-Z0-9_]*=.*$","type":"string"},"maxItems":50,"type":"array"},"name":{"description":"App name","maxLength":63,"minLength":1,"pattern":"^[a-z0-9-]+$","type":"string"},"path":{"description":"Project directory or ample.toml service","maxLength":512,"minLength":1,"type":"string"},"release_command":{"description":"Migration command run before activation","maxLength":512,"type":"string"}},"required":["name","path"],"type":"object"},"outputSchema":null,"workflowSteps":[{"title":"Build and start","body":"dotnet publish -c Release -o out in the builder, then dotnet <entry>.dll on the dotnet-10 template with ASPNETCORE_URLS bound to PORT; the server must bind 0.0.0.0 on PORT."},{"title":"Read DATABASE_URL at runtime","body":"Open connections from the environment inside handlers or a pool; omit DATABASE_URL to auto-provision a managed database or pass --env DATABASE_URL=... for an existing one."},{"title":"Verify","body":"Fetch the live URL and /p/relational-records on the example; on failure read the build and runtime logs.","command":"ample logs <deployment_id> --kind build"}],"examples":[{"title":"ASP.NET Core pattern fixture","description":"Verified database connection on ASP.NET Core.","sourceRef":"tests/deploy-canaries/asp-net-core-patterns"}],"successChecks":[{"description":"app responds on its public URL","kind":"http_get","path":"/","expect":"ample canary asp net core patterns"},{"description":"relational-records check from the example","kind":"http_get","path":"/p/relational-records","expect":"see the pattern fixture checks"}],"limitations":["Verified on the dotnet-10 template at s-1vcpu-1gb.","Managed PostgreSQL 16 with pgvector."],"costEstimate":{"currency":"USD","monthlyAmount":10.0,"authoritative":true,"basis":"size prices from pricing.toml (loaded by the API) at build revision 3a3dfe06151688a20d397caac2aa66e562c23eb0","components":[{"name":"app server","size":"s-1vcpu-1gb","quantity":1.0,"monthlyAmount":5.0},{"name":"managed PostgreSQL database","size":"s-1vcpu-1gb","quantity":1.0,"monthlyAmount":5.0}],"note":"Upper-bound monthly price of the tested sizes. Buckets are allocation-priced per quota and not included."},"evidenceSummary":[{"kind":"canary_run","summary":"ASP.NET Core pattern fixture deployed on Ample (dotnet publish -c Release -o out in the builder, then dotnet <entry>.dll on the dotnet-10 template with ASPNETCORE_URLS bound to PORT); for this guide: a managed PostgreSQL database auto-provisioned and injected as DATABASE_URL, with real queries succeeding at request time (records=ok).","observedAt":"2026-11-06T00:41:08Z","implementationRevision":"7360fc06ef21","expiresAt":"2027-05-05T00:41:08Z","scope":{"checks":["/p/relational-records"],"template":"dotnet-10"}}],"lastVerifiedAt":"2026-11-06T00:41:08Z","mcpBinding":{"registryRef":"mcp:ample_deploy","toolName":"ample_deploy","schemaHash":"0802c329be823fa0695460cf73206d47a6fa0efa57417c386c34b6614a92ea5f","observedAt":"2026-11-06T06:16:17.558478534+00:00","implementationRevision":"4558e9477d09","requiredScopes":["servers:write","databases:read"],"bindingState":"current"},"unknowns":[],"formats":{"html":"https://ample.computer/guides/asp-net-core/database-connection","markdown":"https://ample.computer/guides/asp-net-core/database-connection.md","json":"https://api.ample.computer/v1/catalog/recipes/page%3Aguides%3Aasp-net-core%3Adatabase-connection"},"nextActions":[{"actionId":"browse-catalog","label":"Browse the catalog index","operationId":"catalog_index","method":"GET","relativePath":"/v1/catalog","origin":"api","parameters":{},"requiresAuthentication":false,"requiresApproval":false},{"actionId":"search-recipes","label":"Search published recipes by intent, stack and constraints","operationId":"search_recipes","method":"POST","relativePath":"/v1/catalog/search","origin":"api","parameters":{"body":{"limit":5,"query":"Connect Postgres for ASP.NET Core"}},"requiresAuthentication":false,"requiresApproval":false},{"actionId":"plan:page:guides:asp-net-core:database-connection","label":"Prepare a side-effect-free deployment plan for an authorized project","operationId":"plan_deployment","method":"POST","relativePath":"/v1/catalog/plan","origin":"api","parameters":{"body":{"inputs":{},"projectId":"<workspace or server id you own>","recipeId":"page:guides:asp-net-core:database-connection","recipeRevision":"r1"}},"requiresAuthentication":true,"requiresApproval":false},{"actionId":"auth-setup","label":"Read the existing agent authentication setup","operationId":"existing_auth_setup","method":"GET","relativePath":"/mcp/setup","origin":"api","parameters":{},"requiresAuthentication":false,"requiresApproval":false},{"actionId":"browse:stack:framework-asp-net-core","label":"Browse ASP.NET Core","operationId":"browse_node","method":"GET","relativePath":"/v1/catalog/nodes/stack%3Aframework-asp-net-core","origin":"api","parameters":{"nodeId":"stack:framework-asp-net-core"},"requiresAuthentication":false,"requiresApproval":false},{"actionId":"browse:intent:connect-app-to-database","label":"Browse Connect app to database","operationId":"browse_node","method":"GET","relativePath":"/v1/catalog/nodes/intent%3Aconnect-app-to-database","origin":"api","parameters":{"nodeId":"intent:connect-app-to-database"},"requiresAuthentication":false,"requiresApproval":false},{"actionId":"browse:pattern:relational-records","label":"Browse Relational records","operationId":"browse_node","method":"GET","relativePath":"/v1/catalog/nodes/pattern%3Arelational-records","origin":"api","parameters":{"nodeId":"pattern:relational-records"},"requiresAuthentication":false,"requiresApproval":false}]}