搞定打包时候,把连接字符串写入到web。config
在安装完数据库的时候,把连接字符串写入到web。config
安装数据库考参考
ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.2052/vsintro7/html/vxwlkwalkthroughusingcustomactiontocreatedatabaseduringinstallation.htm
要把连接字符串写入到web。config
注意在输出的时候添加两个主输出:
web项目的主输出和数据库安装工程的主输出
重载下安装类的 Install 方法:
public override void Install(System.Collections.IDictionary stateSaver)
{
Assembly asm = Assembly.GetExecutingAssembly();
DataSet ds = new DataSet();
string strPath = asm.Location;
string[] ary = strPath.Split('\\');
ary[ary.Length-1] = "web.config";
strPath = string.Join("\\", ary);
if (System.IO.File.Exists(strPath))
ds.ReadXml(strPath);
MessageBox.Show(ds.GetXml());
base.Install(stateSaver);
}
因为 DataSet.ReadXml(...);的时候, web.config 已经被安装上去了.
再在这里用 DOM 也好, DataSet 也好, TextReader&TextWriter 也好等等,
将web.config 的连接串的键值给改一改就行了.