异常:带有 CLSID {} 的 COM 对象无效或未注册
今天处理调试打印程序的时候,看到这个异常:
代码:
try { string strApplyEmpno=""; string strApplyDeptCode=""; StringBuilder sb = new StringBuilder (); sb.Append ("SELECT DLRMSTAPPLY.*, AMM010.m010_name_c AS DLRCORPNAME, ") .Append (" EMPLIST.notes_account AS DLREMPNOTES, EMPLIST.ext_no AS DLREMPTELEXT, ") .Append (" EMPACCT.emp_name AS DLRACCTNAME, EMPACCT.ext_no AS DLRACCTEXT, ") .Append (" ProjMappingDD.ItemMXDescCN as ItemDesc, CODE.cdDesc AS DLRTAXTYPENAME ") .Append (" FROM DLRMSTAPPLY INNER JOIN ") .Append ("OPENQUERY(") .Append (strstkdbLinkgServerName) .Append (", 'SELECT m010_co_code, m010_name_c FROM AMM010') AMM010 ") .Append (" ON DLRMSTAPPLY.DLRCO = AMM010.m010_co_code INNER JOIN ") .Append ("OPENQUERY(") .Append (strstkdbLinkgServerName) .Append (", 'SELECT * FROM EMPLIST') EMPACCT ON ") .Append (" DLRMSTAPPLY.DLRACCT = EMPACCT.empno LEFT OUTER JOIN ") .Append ("OPENQUERY(") .Append (strstkdbLinkgServerName) .Append (", 'SELECT * FROM EMPLIST') EMPLIST ON ") .Append (" DLRMSTAPPLY.DLREMPNO = EMPLIST.empno LEFT OUTER JOIN ") .Append (" ProjMappingDD ON DLRMSTAPPLY.DLRPRODLINE = ProjMappingDD.ItemMXCode INNER JOIN ") .Append (" (SELECT cdDesc, cdCode FROM CODE WHERE (cdType = '进项凭证来源')) CODE ON DLRMSTAPPLY.DLRTAXTYPE = CODE.cdCode ") .Append (" WHERE DLRFID='" + strDlrfid + "' "); DataSet dsDlrapplyRPTHead = db.GetDataSet (strConnectionString, sb.ToString(), "DLRMSTAPPLY"); DataView dvDlrapplyRPTHead = dsDlrapplyRPTHead.Tables["DLRMSTAPPLY"].DefaultView; //记录 请款部门代码, 後面明细要用 strApplyEmpno = dvDlrapplyRPTHead[0]["DLREMPNO"].ToString().Trim(); strApplyDeptCode = dvDlrapplyRPTHead[0]["DLRDEPTCODE"].ToString().Trim(); //准备报表要用的 dsDlrapplyRPTDtl sb.Remove(0,sb.Length); sb.Append("SELECT DLRDTLAPPLY.*, DLRMSTAPPLY.* FROM DLRMSTAPPLY INNER JOIN ") .Append(" DLRDTLAPPLY ON DLRMSTAPPLY.DLRFID = DLRDTLAPPLY.DLDFID") .Append(" where DLRMSTAPPLY.DLRFID = '" + strDlrfid + "'"); DataSet dsDlrapplyRPTDtl = db.GetDataSet(strConnectionString, sb.ToString(), "DLRDTLAPPLY"); DataView dvDlrapplyRPTDtl = dsDlrapplyRPTDtl.Tables[0].DefaultView; //等等其他DataSet... mrViewer.Visible = true; engine = mrViewer.Engine; string strRootPath = Application["ReportRoot"].ToString(); engine.RootPath=strRootPath; //加入要列印的报表,注意这里的engine对象 engine.AddDataTable ("dsDlrapplyRPTHead",dvDlrapplyRPTHead.Table); engine.AddDataTable ("dsDlrapplyRPTDtl", dvDlrapplyRPTDtl.Table); engine.AddDataTable ("dsDlrapplystatrec", dtSignList); engine.AddDataTable ("dsDLRDEPTDIVDTL", dsDLRDEPTDIVDTL.Tables["dsDLRDEPTDIVDTL"]); engine.Bind("/flowfund/flowFundApplyPRN.mrf"); string strPath = strFilePathString + "Funddownload\\"; engine.ExportFile (strPath + "\\" + strDlrfid + ".pdf", "", "", ""); } catch (Exception ex) { ucMsg.Log(ExceptionMessage.GetExceptionMessage(ex)); } finally { ucMsg.CheckMessage(); }
添加监视发现ex.message的异常信息如下:
百度查询是:
1、先在服务器上装OFFICE2000软件(也可以不装),但要有msowc.dll;
2、将msowc.dll文件拷到WINNT/system32/下面;
3、注册msowc.dll控件,如果是OWC9的话,regsvr32 -s msowc.dll 注册一下.
试了一下,并没有任何影响,还是报异常,接着看,
其实这个回答并不针对性,也不完整,只是针对一个office的DLL的是否注册问题,根本问题在于,
可能是由于工程需要第三方控件.而且控件不是.NET开发的.所以需要注册DLL
例如:要手工注册“E:\\CPCW.dll”,只需在“开始→运行”中键入“Regsvr32 E:\\CPCW.dll”,单击“确定”按钮后会弹出提示信息“DllRegisterServer in CPCW.dll succeeded”,说明组件注册成功;
如果要卸载此组件,在“开始→运行”中键入“Regsvr32 /u E:\\CPCW.dll”即可。
然后发现代码里确实引用了一个项目,点击异常方法AddDataTable():
using Ming.WebReport;
该页面print.aspx页面:html标记:
<%@ Register TagPrefix="uc1" TagName="InfoControl" Src="../usercontrol/InfoControl.ascx" %> <%@ Register TagPrefix="uc1" TagName="MsgControl" Src="../usercontrol/MsgControl.ascx" %> <%@ Register TagPrefix="Ming" Namespace="Ming.WebReport" Assembly="Ming.WebReport" %> <%@ Page language="c#" Codebehind="flowfundPrint.aspx.cs" AutoEventWireup="false" Inherits="finweb.page.flowfund.flowfundPrint" %>
但是一般来说,用C#做成的DLL是一种“伪DLL",不能通过regsvr32进行注册,如果你要在其他的.NET项目中使用该DLL,只要在项目中进行引用就可以了。
待续。