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;