Search results
30 cze 2011 · You can use this method to get connection string using System; using System.Configuration; private string GetConnectionString() { return ConfigurationManager.ConnectionStrings["MyContext"].ConnectionString; }
26 maj 2011 · Then you can use this Method that returns the connection string to be ready to passed to the sqlconnection object to continue your work as follows: private string ReturnConnectionString() { // Put the name the Sqlconnection from WebConfig.. return ConfigurationManager.ConnectionStrings["DBWebConfigString"].ConnectionString; }
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");
23 lip 2022 · Example: Retrieve a Connection String by Name. This example demonstrates how to retrieve a connection string from a configuration file by specifying its name. The code creates a ConnectionStringSettings object, matching the supplied input parameter to the ConnectionStrings name.
Gets the specified connection string from the specified configuration. Shorthand for GetSection ("ConnectionStrings") [name].
The context is typically configured in Program.cs with the connection string being read from configuration. Note the GetConnectionString method looks for a configuration value whose key is ConnectionStrings:<connection string name>. GetConnectionString requires the Microsoft.Extensions.Configuration namespace.
Get connection string using ConnectionStrings property of ConfigurationManager class. string connectionString = ConfigurationManager.ConnectionStrings[" MyConnection "].ConnectionString; Where MyConnection is the name of the connection as specified in the config file.