dotnet / dotnet/EntityFramework.Docs

Show more examples of obtaining and setting connection strings

Open
#1,083 3 comments 4 reactions 0 assignees View on GitHub
area-context-management
Dominant language
Mermaid
Stars
1.7k
Forks
2k
Avg merge
7d 23h
Merged PRs (30d)
16

Description

What if I need to use a connection string from the config file? like, you know,
```
public ApplicationDbContext CreateDbContext(string[] args)
{
var builder = new DbContextOptionsBuilder();

builder.UseSqlServer( --> Configuration.GetConnectionString("DefaultConnection") <-- );

return new ApplicationDbContext(builder.Options);
}
```
---
#### Document Details

⚠ *Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.*

* ID: 2fa64390-1232-8dd3-f170-7d5c68e29ad9
* Version Independent ID: 245bbba8-3102-4a66-15eb-650e05eb9e62
* Content: [Design-time DbContext Creation - EF Core](https://docs.microsoft.com/en-us/ef/core/miscellaneous/cli/dbcontext-creation)
* Content Source: [entity-framework/core/miscellaneous/cli/dbcontext-creation.md](https://github.com/aspnet/EntityFramework.Docs/blob/master/entity-framework/core/miscellaneous/cli/dbcontext-creation.md)
* Product: **entity-framework**
* GitHub Login: @bricelam
* Microsoft Alias: **bricelam**

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.