Search results
You can do this with the GetConnectionString extension-method: string conString = Microsoft .Extensions .Configuration .ConfigurationExtensions .GetConnectionString(this.Configuration, "DefaultConnection"); System.Console.WriteLine(conString); or with a structured-class for DI:
Gets the specified connection string from the specified configuration. Shorthand for GetSection ("ConnectionStrings") [name].
Note the GetConnectionString method looks for a configuration value whose key is ConnectionStrings:<connection string name>. GetConnectionString requires the Microsoft.Extensions.Configuration namespace.
14 lis 2024 · Zwróć uwagę, że metoda GetConnectionString szuka wartości konfiguracji, której kluczem jest ConnectionStrings:<connection string name>. GetConnectionString wymaga przestrzeni nazw Microsoft.Extensions.Configuration .
31 sty 2024 · Then, let’s use the GetConnectionString() method of the Configuration object to read our connection string from the settings file: IConfiguration configuration = builder.Build(); var connString = configuration.GetConnectionString("ProductsDb");
15 cze 2024 · var connectionString = configuration.GetConnectionString("DefaultConnection"); Here, we can use the IConfiguration to help us to retrieve the connection string from appsettings.json . Then, we assign the result to a variable just for learning purposes.
Note the GetConnectionString method looks for a configuration value whose key is ConnectionStrings:<connection string name>. GetConnectionString requires the Microsoft.Extensions.Configuration namespace.