vs in C # Three ways to read the app. Config database configuration string (GO) http://hi.baidu.com/mindox/item/3278dc352c7ba68fb80c0389http//www.blogjava.net/keweibo/articles/391207.htmlthree ways to configure a database configuration string in VS2008 or VS2005 VS2008 when you create a form program, if you add a data source that automatically writes the connection string in the config file App. Config, the string will be used when you use the dataset. Sqldataaparter,sqlconnection, such as the shadow prompts you to choose, or a new string. There are three ways to get this string in code: The app. Config content:<?xml version="1.0"encoding="Utf-8"?><configuration> <configSections> </configSections><appSettings> <add key="ConnectionString"Value="Data source= your database (localhost available, if it is the express development version must be. \sqlexpress); Initial catalog= database name; User id= username; Password= your own password/><add key="TemplatePath"Value="Template"/></appsettings><connectionstrings> <add name="SxzzManager.Properties.Settings.sxzzConnectionString"connectionString="data source= your database, Initial catalog= database name; User Id=sa; Password= your own code."ProviderName="System.Data.SqlClient"/> <add name="testconnectionstring"connectionstring="data source= your database, Initial catalog= database name; User Id=sa; Password= your own code."ProviderName="System.Data.SqlClient"/> </connectionStrings></configuration>Description: Where the1"<appSettings> <add key="ConnectionString"Value="Data source= your database (localhost available, if it is the express development version must be. \sqlexpress); Initial catalog= database name; User id= username; Password= your own password/><add key="TemplatePath"Value="Template"/></appsettings>to be added by hand. The2"<add name="SxzzManager.Properties.Settings.sxzzConnectionString"connectionString="data source= your database, Initial catalog= database name; User Id=sa; Password= your own code."ProviderName="System.Data.SqlClient"/>The content that is automatically generated when you add a data source in VS2008. The3"<add name="testconnectionstring"connectionstring="data source= your database, Initial catalog= database name; User Id=sa; Password= your own code."ProviderName="System.Data.SqlClient"/>added for manual. To obtain the1The connection string shown in the following statement:stringconstring = system.configuration.configurationsettings.appsettings["ConnectionString"]; stringconstring = system.configuration.configurationmanager.appsettings["ConnectionString"], to obtain the2There are two ways to connect the string shown in<1:stringConstr = system.configuration.configurationmanager.connectionstrings["SxzzManager.Properties.Settings.sxzzConnectionString"]. ToString (); <2:stringConstr = sxzzmanager.properties.settings.default["sxzzconnectionstring"]. ToString ();//" where" sxzzconnectionstring "can be displayed in the dialog box that pops up in the VS2008 menu =" Project = "Property =" set = "name. is actually the string that follows the last point in "SxzzManager.Properties.Settings.sxzzConnectionString". To obtain the3The connection string shown in the "2a string in the "stringConstr = configurationmanager.connectionstrings["testconnectionstring"]. ToString (); stringConstr = configurationmanager.connectionstrings["testconnectionstring"]. ConnectionString: If vs does not recognize the ConfigurationManager class, you need to add a "system.configuration" reference to the reference
vs in C # Three ways to read the app. Config database configuration string (GO)