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>
......
......
..........
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>
......
......
..........