What's wrong at the follow function for change web.config file?

B

Benny Ng

Dear All,

Modify1("SqlServer", "xxxxxxxxxxxxxx");

The error message is program can't find the XML segment <add
name="SqlServer" , But it seems should be runs properly. What's wrong with
the following?


public void Modify1(string key, string strValue)
{
string XPath =
"/configuration/connectionStrings/add[@name='?']";
XmlDocument domWebConfig = new XmlDocument();

domWebConfig.Load((Context.Parameters["targetdir"] +
"\\web.config"));
XmlNode addKey =
domWebConfig.SelectSingleNode((XPath.Replace("?", key)));
if (addKey == null)
{
throw new ArgumentException("Can't find segment <add name='"
+ key + "' connectionString=.../>");
}
addKey.Attributes["connectionString"].InnerText = strValue;
domWebConfig.Save((Context.Parameters["targetdir"] +
"\\web.config"));

}



web.config£º
<?xml version="1.0"?>
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<connectionStrings>
<add name="SqlServer"
connectionString="Database=20061228;Server=Localhost;Integrated
Security=SSPI;" providerName="System.Data.SqlClient" />
</connectionStrings>
......
......
..........
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,007
Latest member
obedient dusk

Latest Threads

Top