VS2005Web引用程序打包并安装数据库.docxVIP

  • 0
  • 0
  • 约5.59千字
  • 约 11页
  • 2016-09-21 发布于重庆
  • 举报
VS2005Web引用程序打包并安装数据库

一个解决方案中可能会包含多个类库项目和一个网站,打包过程如下:1、在【解决方案资源管理器】中【右键-添加-新建项目】,左侧选择【其他类型项目】,右侧选择【安装项目】,如下图:2、点击【确定】后,右侧【文件系统】选项卡中选择【应用程序文件夹】-【添加】-【项目输出】,类库项目选择添加【主输出】,网站选择添加【内容文件】3、在网站的制作过程中可能用到一些其他的BLL组件,也需要添加进来,还是选择【应用程序文件夹】-【添加】-【程序集】,选择你网站BIN文件夹下的一些BLL4、因为要带数据库带包,我是采用打包程序利用系统存储过程附加MDF和LDF文件的方法,所以【应用程序文件夹】中还需要【添加-文件】,将数据库的MDF和LDF文件添加进来,如果安装的需要在控制面板的添加删除程序列表中有图标的话,也需要将ICO图标文件添加进来。5、设置安装项目的常用属性:Author:作者Manufactuer:公司Title:安装程序的标题AddRemoveProgramsIco:设置为添加进来的ICO文件如果不带数据库安装的话,可以将安装项目直接生成就可以了,如果Debug设置为True,则生成的MSI文件在Debug文件夹中,如果为False,生成的MSI文件在Release文件夹中。6、在【解决方案资源管理器】中,右键,添加【新建项目】-【Visual C#】-【类库】,建立数据库安装程序,类库建好后,将默认的Class1.cs文件删除,右键,添加【新建项】-【安装程序类】,下面主要是此类的代码。7、安装程序类的代码:1using System.ComponentModel;2using System.Configuration.Install;3using System.Collections; //以下引入4using System.Collections.Specialized;5using System.Data;6using System.Data.SqlClient;7using System.Reflection;8using System.Xml;910namespace DbClass11{12???? [RunInstaller(true)]13????publicpartialclass InstallDB : Installer14???? {15????????///summary16????????/// 必需的设计器变量,均来自于安装程序的“自定义操作”视图中的设置17????????////summary18????????privatestring hostname;19????????privatestring username;20????????privatestring userpassword;21????????privatestring dbname;2223????????public InstallDB()24???????? {25???????????? InitializeComponent();26???????? }2728????????privatestring CreateSqlStr()29???????? {30????????????string sqlstr = ;31????????????string datafile = Context.Parameters[installdir] + @FlowerShop.mdf;32????????????string logfile = Context.Parameters[installdir] + @FlowerShop_log.ldf;33???????????? sqlstr = EXEC?? sp_attach_db @dbname = + Context.Parameters[dbname] + ,@filename1= + datafile + ,@filename2= + logfile + ;34????????????return sqlstr;35???????? }3637????????privatevoid ExecuteSql(string DatabaseName, string SqlStr)38???????? {39????????????string SqlConnectionStr = @server= + hostname + ;uid= + username + ;pwd= + userpassword;40???????????? SqlConnection myConnection = newSqlConnection(SqlConnectionStr);41??????

文档评论(0)

1亿VIP精品文档

相关文档