以下代碼來自winforms應用程序,它在按鈕事件上打開業務對象6.5的實例,刷新報表,然後將報表中的數據轉儲到csv文件中,然後退出業務對象實例。靜態類和Business Objects COM庫
我第一次運行它完美的代碼,但是如果我再次運行它,我得到就行
boApp.LoginAs(userName, Password, false, null);
引發的異常是「無效的對象」異常。
我認爲這是由於boApp尚未重新初始化,而且這是我對靜態類缺乏知識的問題。
調用的方法是這樣的:
BO_Control.RefreshBusinessObjects(boReportsFolder, boExportsFolder, boReportName, exportFileName, startDate, endDate);
,這是BO_Control類
static class BO_Control
{
static busobj.Application boApp = new busobj.Application();
static busobj.Document testDoc;
public static void RefreshBusinessObjects(string reportFolder, string exportFolder ,string boReportName, string exportFileName, string startDate, string endDate)
{
DateTime BoStart = DateTime.Now;
boApp.LoginAs(userName, Password, false, null);
boApp.Interactive = false;
boApp.Visible = false;
GetData(reportFolder, boReportName, startDate, endDate);
ExportData(exportFolder, exportFileName);
Console.WriteLine("BO_Export took {0} seconds.", DateTime.Now.Subtract(BoStart));
boApp.Quit();
}
static busobj.Document GetData(string reportFolder, string reportName, string startDate, string endDate)
{
Console.WriteLine(reportFolder + reportName);
testDoc = (busobj.Document)boApp.Documents.Open(reportFolder + reportName, true, false, null, null);
//Report Start Date
testDoc.Variables[1].Value = startDate;
//Report End Date
testDoc.Variables[2].Value = endDate;
//Area. Needs to be a semi-colon delimited string
testDoc.Variables[3].Value = "L;B;H;";
testDoc.Refresh();
return testDoc;
}
static void ExportData(string exportFolder, string exportFileName)
{
testDoc.Reports.get_Item(1).ExportAsText(exportFolder + exportFileName);
//2 = DoNotSaveChanges
testDoc.Close(2);
}
}
生氣,這是從過去的爆炸。這行應該被設置,這將關閉所有的業務對象交互boApp.Interactive = false;你是否也確保boApp.LoginAs(userName,Password,false,null)中的用戶名和密碼是正確的;方法? – MrBliz 2014-03-24 15:10:37
我想我的用戶名和密碼是正確的,請通過下面的鏈接看我的代碼,如果我點擊BO登錄diaglog的確定按鈕,博應用程序將照常運行 [點擊此處查看代碼](http:// www.forumtopics.com/busobj/viewtopic.php?t=219784&sid=027f230af85e9b74e8fccff138288724) – user1994358 2014-03-25 01:47:06
我希望我可以進一步幫助您,但我無法再訪問Business Objects 6.5來測試它。 – MrBliz 2014-04-08 09:11:38