Dit artikel is een spiegelartikel van machinevertaling, klik hier om naar het oorspronkelijke artikel te gaan.

Bekijken: 22253|Antwoord: 0

[Bron] C# leest en stelt de connectionstring in app.config in

[Link kopiëren]
Geplaatst op 09-05-2015 17:03:45 | | |

//第一种获取连接字符串的方法
Properties.Settings connset = Properties.Settings.Default;
constr = connset. ConnectionString;
     
         
//第二种获取连接字符串的方法
ConnectionStringSettings instellingen = ConfigurationManager.ConnectionStrings["ConnectionString"];
String str = instellingen. ConnectionString;
//第三种获取连接字符串的方法
XmlDocument doc = nieuw XmlDocument();
Dokter. Load(".. //.. App.config");
XmlNode root = doc. SelectSingleNode("configuration");
XmlNode-knoop = wortel. SelectSingleNode("connectionStrings/add[@name='ConnectionString']");
XmlElement el = knoop als XmlElement;
String str = EL. GetAttribute("connectionString");
//在程序中设置连接字符串
Verstand. ConnectionString = "Data Source=orcl; Persist Security Info=Waar; Gebruiker ID=xhfoc; Wachtwoord=foc; Unicode=Waar";
Verstand. Save();
Om het Settings.settings.cs-bestand onder de naamruimte Properties met deze methode te wijzigen, voeg je de volgende code toe:
[global::System.Configuration.ApplicationScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.SpecialSettingAttribute(global::System.Configuration.SpecialSetting.ConnectionString)]
[global::System.Configuration.DefaultSettingValueAttribute("Data Source=orcl; Persist Security Info=Waar; Gebruiker ID=xhfoc; Wachtwoord=foc; Unicode=Waar")]
         
publieke string ConnectionString
{
     Toevoegen
     {
         return ((string)(this["ConnectionString"]));
     }
     Set
     {
         this["ConnectionString"] = waarde;
     }
}
              
Methoden om het profiel te wijzigen         
XmlDocument doc = nieuw XmlDocument();
Dokter. Load(".. //.. App.config");
XmlNode root = doc. SelectSingleNode("configuration");
XmlNode-knoop = wortel. SelectSingleNode("connectionStrings/add[@name='ConnectionString']");
XmlElement el = knoop als XmlElement;
El. SetAttribute("connectionString", "Data Source=orcl; Persist Security Info=Waar; Gebruiker ID=xhfoc; Wachtwoord=foc; Unicode=Waar");
Dokter. Save(".. //.. App.config");




Vorig:Gisteren heb ik iets verkeerd gedaan met Linq
Volgend:Het type "System.Data.Linq.DataContext" wordt gedefinieerd in de niet-gerefereerde assembly. Moet een antwoord toevoegen aan het programma...
Disclaimer:
Alle software, programmeermaterialen of artikelen die door Code Farmer Network worden gepubliceerd, zijn uitsluitend bedoeld voor leer- en onderzoeksdoeleinden; De bovenstaande inhoud mag niet worden gebruikt voor commerciële of illegale doeleinden, anders dragen gebruikers alle gevolgen. De informatie op deze site komt van het internet, en auteursrechtconflicten hebben niets met deze site te maken. Je moet bovenstaande inhoud volledig van je computer verwijderen binnen 24 uur na het downloaden. Als je het programma leuk vindt, steun dan de echte software, koop registratie en krijg betere echte diensten. Als er sprake is van een inbreuk, neem dan contact met ons op via e-mail.

Mail To:help@itsvse.com