cmgtech
asked on
Get crystal report data into XML format somehow using VB.NET
This is sort of a repost but a little more educated this time... I have crystal reports that I want to get into XML format. I can achieve this using CRAXDRT COM object. Using all this stuff: CrystalDecisions.CrystalRe ports.Engi ne, CrystalDecisions.ReportSou rce, CrystalDecisions.Shared.
The reason I want to use the .NET parts is because I get a bizarre error message sometimes when trying to export to XML in CRAXDRT: -2147184634 This property is currently in a read-only state and cannot be modified. This only happens when I try to filter by date... I think. I cannot reproduce this error all the time. It craps out pretty randomly and I cannot figure out why. No incidents for 3 weeks and then I can't get the app to run for a week.
CRAXDRT has an XML export method built in and it is mind boggling that the .NET component does not. I really think there should be a way to do this and I am going crazy because I have pretty much written off using CRAXDRT since I cannot figure out for the life of me what the issue is. If there is an extra component that I need to use or could buy, please inform me as I am scared I might start crying at work int he next few days if this doesen't work for me.
It's really not that bad but getting close.
My .NET component code works fine and I havent gotten any error messages yet, I just need to get this data into XML.
CRAXDRT Code:
Called with
i = 0
Do While i <= arr.Length - 1
GetSG2_Data(arr(i), i, lastrun)
i += 1
Loop
'arr(i) is 7 in length.
Private Function Get_Data(ByVal arr As String, ByVal index As Integer, ByVal lastrun As String) As Boolean
On Error GoTo Error_code
Dim rpt As CRAXDRT.Report
Dim rpt_nd As MSXML2.IXMLDOMNode
Dim filter_nd As MSXML2.IXMLDOMNode
Dim cr As CRAXDRT.Application
Dim userid, pwd As Object
'new application
cr = New CRAXDRT.Application()
'crystal login info
userid = ""
pwd = ""
'open specified report
rpt = cr.OpenReport("S:\c\tech\R eports\" & arr & ".rpt")
'only log in at application level if it is the first file, else max simultaneous users error
rpt.Database.Tables(1).Con nectBuffer String = "Provider=MSDAORA;;Data Source=w514p;;User ID=" & userid & ";;Password=" & pwd & ";;Locale Identifier=1033;;OLE DB Services=-5"
rpt.DiscardSavedData()
'5/6/2003 12:00:00AM ---> DateTime(Y,M,D,H,M,S)
'sets filter to the get all updates and inrts from last run date
'lastrun = 2004,11,01,00,00,00 in this case
If index = 3 Or index = 0 Then
Else
rpt.RecordSelectionFormula = "{Command.UPDATE_DATE} >= DateTime(" & lastrun & ") OR {Command.INSERT_DATE} >= DateTime(" & lastrun & ")"
End If
'***end filter section
rpt.ReadRecords()
'export xml from crystal
rpt.ExportOptions.Destinat ionType = CRAXDRT.CRExportDestinatio nType.crED TDiskFile
rpt.ExportOptions.FormatTy pe = CRAXDRT.CRExportFormatType .crEFTXML
rpt.ExportOptions.XMLFileN ame = "c:\xml\" & arr & ".xml"
rpt.Export(False)
rpt = Nothing
cr = Nothing
Exit_code:
Exit Function
Error_code:
logger.WriteLine("Get\Erro r @ " & Now() & ": " & Err.Number & vbTab & Err.Source & vbTab & Err.Description, EventLogEntryType.Error)
Resume Exit_code
End Function
The reason I want to use the .NET parts is because I get a bizarre error message sometimes when trying to export to XML in CRAXDRT: -2147184634 This property is currently in a read-only state and cannot be modified. This only happens when I try to filter by date... I think. I cannot reproduce this error all the time. It craps out pretty randomly and I cannot figure out why. No incidents for 3 weeks and then I can't get the app to run for a week.
CRAXDRT has an XML export method built in and it is mind boggling that the .NET component does not. I really think there should be a way to do this and I am going crazy because I have pretty much written off using CRAXDRT since I cannot figure out for the life of me what the issue is. If there is an extra component that I need to use or could buy, please inform me as I am scared I might start crying at work int he next few days if this doesen't work for me.
It's really not that bad but getting close.
My .NET component code works fine and I havent gotten any error messages yet, I just need to get this data into XML.
CRAXDRT Code:
Called with
i = 0
Do While i <= arr.Length - 1
GetSG2_Data(arr(i), i, lastrun)
i += 1
Loop
'arr(i) is 7 in length.
Private Function Get_Data(ByVal arr As String, ByVal index As Integer, ByVal lastrun As String) As Boolean
On Error GoTo Error_code
Dim rpt As CRAXDRT.Report
Dim rpt_nd As MSXML2.IXMLDOMNode
Dim filter_nd As MSXML2.IXMLDOMNode
Dim cr As CRAXDRT.Application
Dim userid, pwd As Object
'new application
cr = New CRAXDRT.Application()
'crystal login info
userid = ""
pwd = ""
'open specified report
rpt = cr.OpenReport("S:\c\tech\R
'only log in at application level if it is the first file, else max simultaneous users error
rpt.Database.Tables(1).Con
rpt.DiscardSavedData()
'5/6/2003 12:00:00AM ---> DateTime(Y,M,D,H,M,S)
'sets filter to the get all updates and inrts from last run date
'lastrun = 2004,11,01,00,00,00 in this case
If index = 3 Or index = 0 Then
Else
rpt.RecordSelectionFormula
End If
'***end filter section
rpt.ReadRecords()
'export xml from crystal
rpt.ExportOptions.Destinat
rpt.ExportOptions.FormatTy
rpt.ExportOptions.XMLFileN
rpt.Export(False)
rpt = Nothing
cr = Nothing
Exit_code:
Exit Function
Error_code:
logger.WriteLine("Get\Erro
Resume Exit_code
End Function
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I really cannot believe that this can happen. It is embarassing that even though I own CR 9 Developer Pro and can export using the COM object, I can't use the .NET version. Dammit.
Thanks guys.
Thanks guys.
That was their intent with CR.Net. To create a desire to get the other features.
Glad i could help
mlmcc
Glad i could help
mlmcc
http://support.businessobjects.com/communityCS/TechnicalPapers/cr9feat_ver.pdf
You might be able to trick it by including th CR8 XML export dll.
mlmcc