Read the solution web in the [C # Common Code] class library. Config string

Source: Internet
Author: User
Tags connectionstrings

Methods for reading strings in the solution Web. config file for a class library
I. Methods of reading key-value pairs;
1. Adding references
Using System.Configuration;
2.web. Config configuration section
<appSettings>
<!--onsite maintenance from the current month forward a few months--
<add key= "Crossmonthnum" value= "2"/>
</appSettings>
3. Code
public static string Fileuploadpath
{
Get
{
return system.web.configuration.webconfigurationmanager.appsettings["Filestorepath"];
return configurationmanager.appsettings["Filestorepath"];
}
}


Two. Read the database connection string
1. Adding references
Using System.Configuration;
2.web. Config configuration section

<connectionStrings>
<!--oracel Link--
<add name= "erp_ft800" connectionstring= "metadata=res://*/erp.csdl|res://*/erp.ssdl|res://*/erp.msl;provider= Oracle.manageddataaccess.client;provider connection String=&quot;data source=ft8000; password=fterp201501!!; PERSIST SECURITY info=true; USER id=ft800&quot; "providername=" System.Data.EntityClient "/>
<add name= "Ftce_accs_systemcon" connectionstring= "Data source=192.168.10.611;initial Catalog=FTCE_ACCS; Persist Security info=true; User Id=sa; [Email protected] "providername=" System.Data.SqlClient "/>

<add name= "ftceoracle" connectionstring= "Data Source=ftcesys; Persist Security info=true; User Id=lqmuser; Password=qmuser "providername=" System.Data.OracleClient "/>
<!--ERP Database interface---
<add name= "erporacle" connectionstring= "Data source=fterp; Persist Security info=true; User id=ft800; password=fterp201501!! "providername=" System.Data.OracleClient "/>
<add name= "erp_readonly" connectionstring= "Data source=fterp; Persist Security info=true; User id=ft800; password=fterp201501!! "providername=" System.Data.OracleClient "/>
<!--temporary use of a mock-up system or other SQL Server database interface--
<add name= "Ftce_interface_systemcon" connectionstring= "Data source=192.168.130.111;initial Catalog=FTCE_ Interface; Persist Security info=true; User Id=sa; [Email protected] "providername=" System.Data.SqlClient "/>
</connectionStrings>
3. Reading the string code
configurationmanager.connectionstrings["Ftce_cw_systemcon"]. ConnectionString

Read the solution web in the [C # Common Code] class library. Config string

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.