我要在安装文件中改写config中的数据联接字,为什么会找不到文件,我如何改?
public override void Install(System.Collections.IDictionary stateSaver)
{ base.Install (stateSaver);
try
{
CreateTxt(this.Context.Parameters["targetdir"]);
System.Diagnostics.Process sqlProcess = new Process();
sqlProcess.StartInfo.FileName = "osql.exe";
sqlProcess.StartInfo.Arguments = string.Format(" -U {0} -P {1} -S {2} -i {3}db.sql", this.Context.Parameters["user"], this.Context.Parameters["pwd"], this.Context.Parameters["dbname"], this.Context.Parameters["targetdir"]);
sqlProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
sqlProcess.Start();
sqlProcess.WaitForExit();
sqlProcess.Close();
}
catch(Exception ce)
{
MessageBox.Show(ce.Message.ToString());
}
try
{
FileInfo fileInfo=new FileInfo(Application.StartupPath+"\\Rnas.exe.config");
if(!fileInfo.Exists)
{
throw new Exception("未能找到相关文件");
} XmlDocument xmlDocument=new XmlDocument();
xmlDocument.Load(fileInfo.FullName);
XmlNodeList nodes=xmlDocument.GetElementsByTagName("add");
for(int i=0;i<nodes.Count;i++)
{
XmlAttribute att=nodes[i].Attributes["key"];
if (att.Value=="strConn")
{
att=nodes[i].Attributes["value"];
att.Value=string.Format("Server=(local);database={0};User ID={1};Password={2};", this.Context.Parameters["dbname"], this.Context.Parameters["user"], this.Context.Parameters["pwd"]);
break;
}
}
xmlDocument.Save(fileInfo.FullName);
}
catch(Exception ce)
{
throw ce;
} }
public override void Install(System.Collections.IDictionary stateSaver)
{ base.Install (stateSaver);
try
{
CreateTxt(this.Context.Parameters["targetdir"]);
System.Diagnostics.Process sqlProcess = new Process();
sqlProcess.StartInfo.FileName = "osql.exe";
sqlProcess.StartInfo.Arguments = string.Format(" -U {0} -P {1} -S {2} -i {3}db.sql", this.Context.Parameters["user"], this.Context.Parameters["pwd"], this.Context.Parameters["dbname"], this.Context.Parameters["targetdir"]);
sqlProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
sqlProcess.Start();
sqlProcess.WaitForExit();
sqlProcess.Close();
}
catch(Exception ce)
{
MessageBox.Show(ce.Message.ToString());
}
try
{
FileInfo fileInfo=new FileInfo(Application.StartupPath+"\\Rnas.exe.config");
if(!fileInfo.Exists)
{
throw new Exception("未能找到相关文件");
} XmlDocument xmlDocument=new XmlDocument();
xmlDocument.Load(fileInfo.FullName);
XmlNodeList nodes=xmlDocument.GetElementsByTagName("add");
for(int i=0;i<nodes.Count;i++)
{
XmlAttribute att=nodes[i].Attributes["key"];
if (att.Value=="strConn")
{
att=nodes[i].Attributes["value"];
att.Value=string.Format("Server=(local);database={0};User ID={1};Password={2};", this.Context.Parameters["dbname"], this.Context.Parameters["user"], this.Context.Parameters["pwd"]);
break;
}
}
xmlDocument.Save(fileInfo.FullName);
}
catch(Exception ce)
{
throw ce;
} }
解决方案 »
- 请问可以计算算术表达式吗?
- 暴初级的问题,希望大家不要鄙视我
- 怎么为Label设置背景图
- 关于两个线程的交互问题,帮帮忙,谢谢!
- Treeview怪问题,无法显示远程用TreeView的东西,
- 我有水晶报表10,要的就来吧。
- 动态生成aspx页面的问题
- C#的winform程序 动态创建checkbox并一行能显示多个chekbox
- 关于C#属性(attribute)的问题和理解
- 用Access数据库,执行两表关联的SQL语句时,总是提示至少缺少一个参数的错误,敬请赐教
- 我想自己指定vs.net运行产生的exe文件的版本信息怎么做。
- 如何在asp.net的page上使用PictureBox显示图片呢?
Rnas.exe.config??