Come recuperare la connection string memorizzata nel web.config in ASP.NET 2.0 in C#

XML: web.config

<connectionStrings>
  <clear />
  <add name="myData"
    providerName="System.Data.SqlClient"
    connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|myDB.MDF;Integrated Security=True;User Instance=True"
  />
</connectionStrings>

C#

//using System.Configuration;
ConnectionStringSettings csdb = ConfigurationManager.ConnectionStrings["myData"];
//System.Web.Configuration.WebConfigurationManager.ConnectionStrings["myData"];
//SqlDbConnection cnn = new SqlConnection(csdb.ConnectionString);
o altri valori

C#

//using System.Configuration;
ConnectionStringSettings csdb = ConfigurationManager.ConnectionStrings["mySetting"];
//System.Web.Configuration.WebConfigurationManager.AppSettings["mySetting"];
//System.Web.Configuration.WebConfigurationManager.GetSection("system.web/authentication");
Nel .NET 2.0 System.Configuration.ConfigurationSettings.AppSettings è deprecato in favore di System.Configuration.ConfigurationManager.AppSettings
Tags:
C#236 Esempi225
Potrebbe interessarti anche: