为什么我在运行windwos服务C#时遇到excel异常? [英] Why I am getting the excel exception on running the windwos service C#?

查看:93
本文介绍了为什么我在运行windwos服务C#时遇到excel异常?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在运行以下代码时遇到异常。它在c#中作为windows服务运行。

它在我的机器上工作正常。使用Excel 2013.

以下是核心代码

   #region SmartPDFCaptureService 
/// < 摘要 >
/// SMART_PDf_CAPTURE_SERVICE_SYNCHRONIZER
/// < / summary >
/// < param name =source > < / param >
/// < param name =e > < / param >
private void SmartPDFCaptureService( object source,ElapsedEventArgs e)
{
WriteServiceLog( + SmartPDFLogCaption + 已输入
+ MethodInfo.GetCurrentMethod()。Name + 方法);
尝试
{
// 从FileStore文件夹中设置的PDF中捕获数据的主要功能
ExtractPDFData();
}
catch (Exception ex)
{
WriteErrorLog(MethodInfo.GetCurrentMethod()。Name + + ex.Message,ex.StackTrace, true );
}
WriteServiceLog( + SmartPDFLogCaption + 已完成 + MethodInfo.GetCurrentMethod()。名称+ < span class =code-string> Method
);
}
#endregion





我尝试过:



#region SmartPDFCaptureService

///< summary>

/// SMART_PDf_CAPTURE_SERVICE_SYNCHRONIZER

///

///< param name =source/>

///< param name =e/>

private void SmartPDFCaptureService(对象源,ElapsedEventArgs e)

{

WriteServiceLog(+ SmartPDFLogCaption +Entered+ MethodInfo.GetCurrentMethod()。Name +Method);

try

{

//从FileStore文件夹中设置的PDF中捕获数据的主要功能

ExtractPDFData();

}

catch(Exception ex)

{

WriteErrorLog(MethodInfo.GetCurrentMethod( ).Name ++ ex.Message,ex.StackTrace,true);

}

WriteServiceLog(+ SmartPDFLogCaption +Finished+ MethodInfo.GetCurrentMethod( ).Name +方法);

}

#endregion

解决方案

可能,它'; sa权限问题 - 服务不在您的用户ID下运行,因此如果您的 ExtractPDFData 方法正在访问文件(很可能),那么您可能需要检查并确保他们所在的文件夹具有足够的权限供所有用户读/写。



但是,根本没有任何代码使用Excel - 如果该方法试图使用Excel来读取PDF文件,那么可能没有安装Excel(或者没有为所有用户安装)在目标计算机上。你为什么用Excel来阅读PDF文件呢?



我们无法为您检查任何内容 - 我们无权访问您的计算机 - 但如果所有这些检查,然后你需要非常具体的错误消息,以及它出现的确切行。


Microsoft不鼓励通过服务或其他方式使用Office程序自动化任务:

https://support.microsoft.com/en-us/kb / 257757 [ ^ ]

I am getting the exception on running below code. It is run as windows service in c#.
It is working fine in my machine. Using Excel 2013.
Below is the core code

#region SmartPDFCaptureService
     /// <summary>
     /// SMART_PDf_CAPTURE_SERVICE_SYNCHRONIZER
     /// </summary>
     /// <param name="source"></param>
     /// <param name="e"></param>
     private void SmartPDFCaptureService(object source, ElapsedEventArgs e)
     {
         WriteServiceLog("" + SmartPDFLogCaption + "Entered " + MethodInfo.GetCurrentMethod().Name + " Method");
         try
         {
             //Main Function to capture data from PDFs set in FileStore Folder
             ExtractPDFData();
         }
         catch (Exception ex)
         {
             WriteErrorLog(MethodInfo.GetCurrentMethod().Name + " " + ex.Message, ex.StackTrace, true);
         }
         WriteServiceLog("" + SmartPDFLogCaption + "Finished " + MethodInfo.GetCurrentMethod().Name + " Method");
     }
     #endregion



What I have tried:

#region SmartPDFCaptureService
/// <summary>
/// SMART_PDf_CAPTURE_SERVICE_SYNCHRONIZER
///
/// <param name="source" />
/// <param name="e" />
private void SmartPDFCaptureService(object source, ElapsedEventArgs e)
{
WriteServiceLog("" + SmartPDFLogCaption + "Entered " + MethodInfo.GetCurrentMethod().Name + " Method");
try
{
//Main Function to capture data from PDFs set in FileStore Folder
ExtractPDFData();
}
catch (Exception ex)
{
WriteErrorLog(MethodInfo.GetCurrentMethod().Name + " " + ex.Message, ex.StackTrace, true);
}
WriteServiceLog("" + SmartPDFLogCaption + "Finished " + MethodInfo.GetCurrentMethod().Name + " Method");
}
#endregion

解决方案

Probably, it';s a permissions issue - a service doesn't run under your user ID, so if your ExtractPDFData method is accessing files (as is likely) then you probably need to check and make sure that the folder they are in has sufficient permissions for all users to read / write.

However, none of that code uses Excel at all - of if the method is trying to use Excel to read PDF file, then it's possible that Excel is not installed (or not installed for all users) on the target machine. Why are you using Excel to read PDF files anyway?

We can't check any of that for you - we don't have access to your computers - but if all of that checks out, then you need to be very much more specific about the error message, and the exact line it occurs on.


Microsoft discourages the use of Office programs by services or other automated tasks:
https://support.microsoft.com/en-us/kb/257757[^]


这篇关于为什么我在运行windwos服务C#时遇到excel异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆