我必须将数据从网页导入到运行 AcuCobol 的会计包中。
它是一个 IIS ASP .NET Core 应用程序。
为了做到这一点,我有一个 VB 程序来执行实际的导入,因为错误报告似乎更好。我遇到了问题,使我将导入转移到独立的应用程序中。 Web 应用程序现在调用它,并将要导入的文件作为参数传递。
在我的开发笔记本电脑(运行 Windows 10)上一切运行良好。但是当我尝试在客户的服务器上运行它(运行 Windows Server 2016)时,导入独立程序失败并出现以下错误:
Exit code 255
Unhandled Exception: System.Exception: Cannot create ActiveX component.
at Microsoft.VisualBasic.Interaction.CreateObject(String ProgId, String ServerName)
at SW.SWImporter.SWImporter.Import(String fullSWPath, String companyName, String importFormatName, String fullSWImportDirectory, String filename, String fullLogfilePathAndName, String SWConfig) in D:\bbrepo\BZJT\Importer\SW\SWImporter.vb:line 29
at RunImportmate.ImportmateProgram.callSWImporter(String fullImportFileName, String importFormatName) in D:\ASG\repo\Importer\RunImportmate\Program.cs:line 75
at RunImportmate.ImportmateProgram.Main(String[] args) in D:\ASG\repo\Importer\RunImportmate\Program.cs:line 37
编辑:添加了更详细的错误产生:
2023-11-07 20:54:57 - ERROR: Retrieving the COM class factory for component with
CLSID {BFBBB600-C4DB-11D2-B11B-74F606C10000} failed
due to the following error: 80070005 Access is denied.
(Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)).
更神秘的是,如果我手动运行独立程序,它运行良好。 只有当我尝试从 IIS 中启动该进程时,才会出现此错误。
这里有一些代码片段,如果您需要更多,请LMK。
执行独立的 IIS 代码:
try
{
string ForwardSlash = @"/";
string BackSlash = @"\";
var ImportmateDirectory = Program.Configuration["SWIMP:ImportmateDirectory"];
var executablePath = ImportmateDirectory + "/RunImportmate.exe";
// Good ol' DOS commands won't accept a /
executablePath = executablePath.Replace(ForwardSlash, BackSlash);
ImportmateDirectory = ImportmateDirectory.Replace(ForwardSlash, BackSlash);
var processStartInfo = new ProcessStartInfo
{
FileName = executablePath,
Arguments = $"\"{filePath}\"",
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false,
CreateNoWindow = true,
WorkingDirectory = ImportmateDirectory // Set the working directory
};
var args = processStartInfo.Arguments;
using var process = new Process
{
StartInfo = processStartInfo
};
process.Start();
// Read standard output and error if needed
string output = await process.StandardOutput.ReadToEndAsync();
string error = await process.StandardError.ReadToEndAsync();
process.WaitForExit();
int exitCode = process.ExitCode;
return exitCode;
}
这是程序代码:
static void Main(string[] args)
{
String FileToImport = args[0];
String importFormatName = System.Configuration.ConfigurationManager.AppSettings["importFormatName"];
String smallNameDirectory = System.Configuration.ConfigurationManager.AppSettings["smTempDirectory"];
string smFileToImport = "tmpImp.txt";
File.Copy(FileToImport, smFileToImport, true); // copy and delete old file
writeLOGFile( writeLOGFile("Renaming " + FileToImport + " To: " + smFileToImport + " to avoid long name issues ");
String result = callSWImporter(smFileToImport, importFormatName);
if (result.ToUpper() == "OK")
{
Console.WriteLine("SWImport was successful");
}
else
{
Console.Error.WriteLine("ERROR: SWImport was NOT successful for File: "
+ FileToImport + "(See LogFile)");
}
} // main end brace
static public string callSWImporter(String fullImportFileName, String importFormatName)
{
String fullSWPath = System.Configuration.ConfigurationManager.AppSettings["fullSWPath"];
String companyName = System.Configuration.ConfigurationManager.AppSettings["companyName"];
String swTempDirectory = System.Configuration.ConfigurationManager.AppSettings["swTempDirectory"];
String importLogPathAndName = System.Configuration.ConfigurationManager.AppSettings["importLogPathAndName"];
String SWConfig = System.Configuration.ConfigurationManager.AppSettings["SWConfig"];
// Call SouthWare AcuGT to import the file
FileInfo ImportFileNameInfo = new FileInfo(fullImportFileName);
String importFileName = ImportFileNameInfo.Name;
SWImporter swImporter = new SWImporter(); // This is a VB.NET class
if (swImporter != null)
{
Console.WriteLine("Create swImporter from SW Object: SUCCESS!");
}
String result = swImporter.Import(fullSWPath,
companyName,
importFormatName,
swTempDirectory ,
importFileName,
importLogPathAndName,
SWConfig);
Console.WriteLine("swImporter.Import COMPLETE. Result = " + result);
return result;
}
如果重要的话,我将独立程序编译为.NET 4.5,AnyCPU,首选 32 位:
编辑:添加了 VB 代码,如果有帮助的话......
Public Function Import(ByVal fullSWPath As String, ByVal companyName As String, ByVal importFormatName As String, ByVal fullSWImportDirectory As String,
ByVal filename As String, ByVal fullLogfilePathAndName As String, SWConfig As String) As String
Dim configFile ' ACUCOBOL-GT config file
Dim AcuGT1 ' ACUCOBOL-GT ActiveX control
Dim retVal ' Return value
Dim chkVal ' Check Paramerter values
Dim imStatus As String ' ImportMate Status
Dim newKey ' New key if new record
Dim acug1 As Object
Dim cstType
configFile = fullSWPath & SWConfig
AcuGT1 = CreateObject("AcuGT.Application")
AcuGT1.Initialize("-c " & configFile & " -le " & fullLogfilePathAndName) 'this is to create a log file
retVal = AcuGT1.Call("I2OPNCOM.OBJ", companyName, importFormatName, fullSWImportDirectory, filename, filename, "", "", imStatus, newKey)
AcuGT1.Shutdown()
Import = imStatus
End Function
如果此问题仅出现在iis上,您可以尝试以下解决方案: