C# 1627-Microsoft.Deployment.WindowsInstaller.InstallerException:函数在执行期间失败
现在,问题是,当我在创建的MSI文件上运行此代码时,最后一次查询(即延迟启动的查询)失败,并给出MSI错误代码1627的异常: Microsoft.Deployment.WindowsInstaller.InstallerException:函数在执行过程中失败。 在Microsoft.Deployment.WindowsInstaller.View.Execute(记录executeParams) 在Microsoft.Deployment.WindowsInstaller.Database.Execute(字符串sql,记录) 位于Microsoft.Deployment.WindowsInstaller.Database.Execute(字符串sqlFormat,对象[]args) 在C:\Users\Chirag Pathak\3D Objects\bizbrain-agent-v7\Installers\msimager\Program.cs中的msimager.Program.updatemsisservice(字符串msi、字符串serviceName、字符串displayName、字符串文件名)处:第96行 下面是我的代码C# 1627-Microsoft.Deployment.WindowsInstaller.InstallerException:函数在执行期间失败,c#,windows-installer,C#,Windows Installer,现在,问题是,当我在创建的MSI文件上运行此代码时,最后一次查询(即延迟启动的查询)失败,并给出MSI错误代码1627的异常: Microsoft.Deployment.WindowsInstaller.InstallerException:函数在执行过程中失败。 在Microsoft.Deployment.WindowsInstaller.View.Execute(记录executeParams) 在Microsoft.Deployment.WindowsInstaller.Database.
class Program
{
private static int msidbServiceConfigEventInstall = 1;
private static int SERVICE_CONFIG_DELAYED_AUTO_START = 3;
private static string BIN_FILE_PATH_X64 = @"C:\Users\Chirag Pathak\3D Objects\bizbrain-agent-v7\x64\Debug\";
private static string MSI_NAME_X64 = "MyTallyApp Agent Installer (x64).msi";
private static string PATH_PREFIX = "C:\\Users\\Chirag Pathak\\3D Objects\\bizbrain-agent-v7\\Installers\\Installers\\";
static void Main(string[] args)
{
UpdateMSIService(MSI_NAME_X64, "BizBrainAgentWindowsService-x64", "MyTallyApp Agent Service (64 bit)", "BizBrainAgentWindowsService-x64.exe");
UpdateMSIService(MSI_NAME_X64, "BizBrainAgentWindowsServiceLauncher-x64", "MyTallyApp Agent Service Launcher (64 bit)", "BizBrainAgentWindowsServiceLauncher-x64.exe");
}
static bool UpdateMSIService(string msi, string serviceName, string displayName, string fileName)
{
string databasePath = PATH_PREFIX + msi;
if (!File.Exists(databasePath))
{
Console.WriteLine("MSI File " + msi + " does not exist!");
return false;
}
using(Database database = new Database(databasePath, DatabaseOpenMode.Direct))
{
try
{
serviceName = "'" + serviceName + "'";
displayName = "'" + displayName + "'";
Microsoft.Deployment.WindowsInstaller.View view = database.OpenView("Select Component_,FileName from File");
view.Execute();
Record[] records = view.ToArray<Record>();
string componentId = "'" + GetComponentId(records, fileName) + "'";
view.Close();
Console.WriteLine("Service ComponentId=:" + componentId);
//Do this after the search
fileName = "'" + fileName + "'";
string sqlDeleteServiceInstall = "DELETE FROM `ServiceInstall` WHERE `ServiceInstall`=" + serviceName;
database.Execute(sqlDeleteServiceInstall);
string sqlInsertServiceInstall = "INSERT INTO `ServiceInstall` (`ServiceInstall`,`Name`,`DisplayName`,`ServiceType`,`StartType`,`ErrorControl`,`Component_`,`Description`) VALUES (" + serviceName + "," + serviceName + "," + displayName + ",16,2,1," + componentId + "," + displayName + ")";
database.Execute(sqlInsertServiceInstall);
string sqlDeleteServiceControl = "DELETE FROM `ServiceControl` WHERE `ServiceControl`=" + serviceName;
database.Execute(sqlDeleteServiceControl);
string sqlInsertServiceControl = "INSERT INTO `ServiceControl` (`ServiceControl`,`Name`,`Event`,`Component_`) VALUES(" + serviceName + "," + serviceName + ",1," + componentId + ")";
database.Execute(sqlInsertServiceControl);
****//For Automatic [Delayed Start]
string sqlInsertMSIServiceConfig = "INSERT INTO `MsiServiceConfig`(`MsiServiceConfig`,`Name`,`Event`,`ConfigType`,`Argument`,`Component_`) VALUES('AutoStartDelayed'," + serviceName + "," + msidbServiceConfigEventInstall + "," + SERVICE_CONFIG_DELAYED_AUTO_START + ",1," + componentId + ")";
database.Execute(sqlInsertMSIServiceConfig);//****//This is the line where exception occures.
return true;
}
catch (Exception e)
{ }
}
}
类程序
{
私有静态int-msidbserviceconfigeeveninstall=1;
专用静态int服务配置延迟自动启动=3;
私有静态字符串BIN_FILE_PATH_X64=@“C:\Users\Chirag Pathak\3D Objects\bizbrain-agent-v7\X64\Debug\”;
私有静态字符串MSI_NAME_X64=“MyTallyApp代理安装程序(X64).MSI”;
私有静态字符串路径\u PREFIX=“C:\\Users\\Chirag Pathak\\3D Objects\\bizbrain-agent-v7\\Installers\\Installers\\”;
静态void Main(字符串[]参数)
{
UpdateMsisService(MSI_NAME_X64,“BizBrainAgentTwinDowsService-X64”,“MyTallyApp代理服务(64位)”,“BizBrainAgentTwinDowsService-X64.exe”);
UpdateMsisService(MSI_NAME_X64,“BizBrainAgentTwinDowserviceLauncher-X64”,“MyTallyApp代理服务启动器(64位)”,“BizBrainAgentWinDowserviceLauncher-X64.exe”);
}
静态bool updatemsis服务(字符串msi、字符串serviceName、字符串displayName、字符串文件名)
{
字符串databasePath=PATH_前缀+msi;
如果(!File.Exists(databasePath))
{
WriteLine(“MSI文件”+MSI+“不存在!”);
返回false;
}
使用(数据库=新数据库(databasePath,DatabaseOpenMode.Direct))
{
尝试
{
serviceName=“””+serviceName+“”;
displayName=“””+displayName+“”;
Microsoft.Deployment.WindowsInstaller.View=database.OpenView(“从文件中选择组件,文件名”);
view.Execute();
Record[]records=view.ToArray();
字符串componentId=“””+GetComponentId(记录,文件名)+“”;
view.Close();
WriteLine(“服务组件ID=:”+ComponentId);
//在搜索之后执行此操作
fileName=“”+fileName+“”;
字符串sqlDeleteServiceInstall=“从`ServiceInstall`中删除,其中`ServiceInstall`=“+serviceName;
执行(sqlDeleteServiceInstall);
字符串sqlInsertServiceInstall=“插入到`ServiceInstall`(`ServiceInstall`、`Name`、`DisplayName`、`ServiceType`、`StartType`、`ErrorControl`、`Component`、`Description`)值(“+serviceName+”、“+serviceName+”、“+DisplayName+”、16,2,1、“+componentId+”、“+DisplayName+”)”);
执行(sqlInsertServiceInstall);
字符串sqlDeleteServiceControl=“从`ServiceControl`中删除,其中`ServiceControl`=”+serviceName;
执行(sqlDeleteServiceControl);
字符串sqlInsertServiceControl=“插入到`ServiceControl`(`ServiceControl`、`Name`、`Event`、`Component`)值(“+serviceName+”、“+serviceName+”、1、”+componentId+”);
执行(sqlInsertServiceControl);
****//用于自动[延迟启动]
字符串sqlinsertmsisserviceconfig=“插入`msisserviceconfig`(`msisserviceconfig`、`Name`、`Event`、`ConfigType`、`Argument`、`Component`)值('AutoStartDelayed'、“+serviceName+”、“+msidbserviceconfiggeveninstall+”、“+SERVICE\u CONFIG\u DELAYED\u AUTO\u START+”、1、“+componentId+”);
database.Execute(sqlInsertMSIServiceConfig);//*****//这是发生异常的行。
返回true;
}
捕获(例外e)
{ }
}
}
{“msiErrorCode”:1627,“类名”:“Microsoft.Deployment.WindowsInstaller.InstallerException”,“消息”:“函数在执行过程中失败”,“数据”:null,“InnerException”:null,“HelpURL”:null,“StackTraceString”:“在Microsoft.Deployment.WindowsInstaller.View.Execute(记录executeParams)\r\n位于Microsoft.Deployment.WindowsInstaller.Database.Execute(字符串sql,记录记录)\r\n位于Microsoft.Deployment.WindowsInstaller.Database.Execute(字符串sqlFormat,对象[]args)\r\n位于MSIMAger.Program.UpdateMsisService(字符串msi,字符串serviceName,字符串displayName,字符串文件名)在C:\Users\Chirag Pathak\3D Objects\bizbrain-agent-v7\Installers\msimager\Program.cs:line 96中,“RemoteStackTraceString”:null,“RemoteStackIndex”:0,“ExceptionMethod”:“8\nExecute\nMicrosoft.Deployment.WindowsInstaller,版本=3.0.0.0,区域性=中性,PublicKeyToken=ce35f76fcda82bad\nMicrosoft.Deployment.WindowsInstaller.View\nVoid执行(Microsoft.Deployment.WindowsInstaller.Record)”,“HResult”:-2146233087,“源”:“Microsoft.Deployment.WindowsInstaller”,“WatsonBucket”:null}如果y