ASP. NET + dll + DLL read the configuration file (access the database and WebService In the DLL)

Source: Internet
Author: User

1. Content of the configuration file nwibms. config:
<? XML version = "1.0" encoding = "UTF-8"?>
<Configuration>
<Add key = "connectionstring"

Value = "Server =.; database = ztibms; trusted_connection = false; uid = WY; Pwd = 123456;"/>
<Add key = "webserviceurl"

Value = "http: // localhost/wywebservice/WebService/tablesearch. asmx"/>
</Configuration>
The configuration file nwibms. config is placed under bin.
2. Obtain the database connection string in DLL
First, the project must reference system. Web to use system. Web. httpcontext. Current. server. mappath to obtain the physical path.

Private string getconnectionstring ()
{
String ret = "";

String file = system. Web. httpcontext. Current. server. mappath ("~ /Bin/nwibms. config ");
Try
{
Using (xmlreader reader = xmlreader. Create (File ))
{
While (reader. readtofollowing ("add "))
{
String key = reader. getattribute ("key ");

If (Key = "connectionstring ")
{
Ret = reader. getattribute ("value ");
}
}
}
}
Catch
{
Ret = "";
}

Return ret;
}

3. Obtain the WebService URL in DLL and change the WebService URL:
You can change the WebService URL at runtime.
String url = geturl ();
Localhost. tablesearch Ts = new localhost. tablesearch ();
TS. url = URL;

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.