在安装过程中运行sql代码的msi安装程序

时间:2013-04-30 21:57:34

标签: windows-installer

在我的网络应用程序(asp.net C#)中,我添加了网页设置应用程序。通过这个Web设置,我需要做两件事:  

1。将文件复制到IIS上的应用程序

 

2。在安装期间运行三个插入语句

我有第二点的问题,不知道如何修复或调试它。 在自定义操作中,我已经在Install文件夹上添加了dll文件(主输出),这几乎就是我在互联网上发现的有关在安装过程中运行SQL脚本的内容。 另外我需要宣布我以这种方式覆盖函数OnAfterInstall:

string connectionString1 = string.Format("Data Source={0};Initial Catalog={1};Integrated Security=True;", Context.Parameters["db"], Context.Parameters["catalog"]);
using (SqlConnection connection = new SqlConnection(connectionString1))
{

string CommandText = "insert into Sealed (Example) values ('now is OK'); ";
SqlCommand com = new SqlCommand(CommandText, connection);  
com.ExecuteNonQuery();                
}     

如果你知道一些很好的教程或书籍,它描述了在安装过程中运行的sql语句,它将对我有很大的帮助

2 个答案:

答案 0 :(得分:2)

如果您的文件被加载到IIS应用程序中,为什么不通过某些XML文件提供INSERT sql,然后在您的应用程序中有一段代码检查文件夹中是否包含应用程序可以在Application_Start上运行的脚本的xml文件

您需要有机制在运行后忽略它们,或删除它们。

答案 1 :(得分:0)

Windows Installer是一个SDK和Windows平台服务,但它并不是一个真正的MSI创作工具。 (ORCA并不算数。)

查看Windows Installer XML(WiX)或InstallShield。它们都在MSI上添加了对SQL连接和脚本执行的支持,而无需您自己编写。