1、选择Windows Installer最高版本) (图10) (图11)5、 选择启动条件(提示:本机必须装至少为IIS 5.1版本)如(图12、13); (图12) (图13)6、 添加许可协议(图14、15、16、17、18、19、20、21); (图14) (图15) (图16)上移到“欢迎使用”下) (图17) (图18) (图19) (图20) (图21)7、 设置数据库信息(图14、22、23、24、25、26) (图22)上移到“许可协议”下) (图23) (图24) (图25)设置数据库连接参数信息(提示:如果没有第四个编辑字段,则设置该字段为隐藏状态)如下 (图26)8、 添
2、加安装类如(图27、28、29、30、31、32) (图27) (图28) (图29) (图30) (图31) (图32)添加的代码如下:using System;usingSystem.Collections;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Configuration.Install;usingSystem.Linq;usingSystem.Xml;usingSystem.Diagnostics;usingSystem.Data;usingSystem.Data.SqlClient;
3、namespaceInstallDB RunInstaller(true)public partial class Installer : System.Configuration.Install.Installer public Installer()InitializeComponent(); public override void Install(System.Collections.IDictionarystateSaver)base.Install(stateSaver); /参数名必须与用户界面的“文本框 A”设置的参数必须一致string server = this.Conte
4、xt.Parametersserver;stringuid = this.Context.Parametersuidstringpwd = this.Context.Parameterspwdstring path = this.Context.Parameterstargetdir string DataName = GDKSHDB; /数据库名称stringconnString = server= + server + uid= + uid + pwd= + pwd + database=+DataName;stringconnStr = database=master string st
5、rMdf = path + fxFrame.mdf/如果是文件大于800M,则必须指定目录,不能用path安装目录stringstrLdf = path + fxFrame_log.ldf / UpdateConConfig(connString, path + web.config);this.CreateDataBase(connStr, DataName, strMdf, strLdf); / / 附加数据库/summaryparam name=strSql数据库连接字符串DataName数据库名称strMdf数据文件路径strLdf日志文件路径private void CreateDa
6、taBase(string connStr, string DataName, string strMdf, string strLdf) String str;SqlConnectionmyConn = new SqlConnection(connStr);str = EXEC sp_attach_db dbname = + DataName + , filename1 = + strMdf + ,filename2= + strLdf + SqlCommandmyCommand = new SqlCommand(str, myConn);myConn.Open();myCommand.Ex
7、ecuteNonQuery();myConn.Close();myConn.Dispose(); / /修改Web项目web.config配置文件的值paramname=conName连接字符串名称conString连接字符串configfilePath设定档路径及名称public static void UpdateConConfig(string conString, string configfilePath)XmlDocumentxmlDoc = new XmlDocument(); /读取设定档xmlDoc.Load(configfilePath); /取得连接字符串的节点XmlNo
8、dexmlNode = xmlDoc.SelectSingleNode(configuration/appSettings/addkey=Connection /修改连接字符串xmlNode.Attributesvalue.InnerText = conString; /保存xmlDoc.Save(configfilePath);9、 添加安装输出如(图33、34、35、36、37、38、39) (图33) (图34) (图35) (图36) (图37) (图38) (图39)指定要传递到安装程序的自定义数据代码如下:/server=CUSTOMTEXTA1 /uid=CUSTOMTEXTA2 /pwd=CUSTOMTEXTA3 /targetdir=TARGETDIR其中的空格必不可少)10、配置项目如(图40、41); (图40) (图41)11、重新生成解决方案,然后从WebSetupDebug目录下拷出安装目录(WebSetup.msi)即可。
copyright@ 2008-2023 冰点文库 网站版权所有
经营许可证编号:鄂ICP备19020893号-2