cancel
Showing results for 
Search instead for 
Did you mean: 

LogOnException thrown when calling ExportToStream

Former Member
0 Kudos

Hi there, <br>

<br>

I am having real problems when calling the ExportToStream method on the ReportDocument class.<br>

<br>

I am trying to load a CrystalReport that is held in a Database field, apply parameters to that report (the values for the parameters) are also held in another database table, and then export the report (complete with the parameterised values) back to another record in the DB.<br>

<br>

All goes swimmingly until I try to call ExportToStream to finally place the report (with params) back in DB. When I get to this call I get a LogOnException thrown (Message: "Logon failed.

Details: 08004:[Sybase][ODBC Driver][SQL Anywhere]Parse error: Invalid or missing keyword near 'DATABASE'

Error in File C:\DOCUME1\BARRY1.ROB\LOCALS~1\Temp\tmp16C {8CF0E4A7-E74C-41DC-BF7E-5871D40432E9}.rpt:

Unable to connect: incorrect log on parameters.").<br>

<br>

The code causing the excpetion is the call to ExportToStream below:<br>

public void ProcessQueuedReports(string connectionString, ProcessQueueMode processMode, string providerName)<br>

{ <br>

<br>

&nbsp; &nbsp; List<ReportQueueDetails> queuedReportList = ReportQueueDetails.GetAllQueuedByPriority(connectionString);<br>

<br>

&nbsp; &nbsp; if (queuedReportList.Count > 0)<br>

&nbsp; &nbsp; {<br>

&nbsp; &nbsp; &nbsp; &nbsp; int numberToProcess = ReturnNumberToProcess(processMode,

queuedReportList.Count);<br>

&nbsp; &nbsp; &nbsp; &nbsp; for (int count = 0; count < numberToProcess; count++)<br>

&nbsp; &nbsp; &nbsp; &nbsp; {<br>

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SetQueueItemAsProcessing(queuedReportList[count]);<br>

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (reportReader.LoadReport(connectionString,

queuedReportList[count].ReportDetailsRef,

queuedReportList[count].ReportQueueDetailsRef, providerName))<br>

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br>

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ExportFormatType outputFormat =

ReturnExportFormatType(queuedReportList[count].ReportFormatTypeCode);<br>

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Stream reportStream = new MemoryStream();<br>

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; reportReader.Report.ReportOptions.EnableSaveDataWithReport = false;<br>

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; reportStream = reportReader.Report.ExportToStream(outputFormat);<br>

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; byte[] reportData = new byte[(int)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; reportStream.Length];<br>

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int numBytesToRead = (int)reportStream.Length;<br>

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int numBytesRead = 0;<br>

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; reportStream.Position = 0;<br>

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; while (numBytesToRead > 0)<br>

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br>

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int n = reportStream.Read(reportData, numBytesRead, numBytesToRead);<br>

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (n == 0)<br>

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;<br>

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; numBytesRead += n;<br>

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; numBytesToRead -= n;<br>

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; queuedReportList[count].ReportOutput = reportData;<br>

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; queuedReportList[count].Update(IyssDateTime.CurrentDatabaseDateTime);<br>

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SetQueueItemAsSuccess(queuedReportList[count]);<br>

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else<br>

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br>

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SetQueueItemAsFailed(queuedReportList[count]);<br>

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>

&nbsp; &nbsp; &nbsp; &nbsp; }<br>

&nbsp; &nbsp; }<br>

}<br>

<br>

This is the LoadReport method called above:<br>

<br>

public bool LoadReport(string connectionString, int reportDetailsRef, int reportQueueRef, string providerName)<br>

{<br>

&nbsp; &nbsp; bool LoadSuccess = false;<br>

&nbsp; &nbsp; ReportDetails report = IyssReportDetails.GetByRef(reportDetailsRef,

connectionString);<br>

&nbsp; &nbsp; byte[] reportData = (byte[])report.ReportData;<br>

&nbsp; &nbsp; int size = reportData.GetUpperBound(0);<br>

&nbsp; &nbsp; string tempFilename = Path.GetTempFileName();<br>

&nbsp; &nbsp; if (tempFilename != "")<br>

&nbsp; &nbsp; {<br>

&nbsp; &nbsp; &nbsp; &nbsp; FileStream fs = new FileStream(tempFilename, FileMode.OpenOrCreate,

FileAccess.Write);<br>

&nbsp; &nbsp; &nbsp; &nbsp; fs.Write(reportData, 0, size);<br>

&nbsp; &nbsp; &nbsp; &nbsp; fs.Close();<br>

&nbsp; &nbsp; &nbsp; &nbsp; try<br>

&nbsp; &nbsp; &nbsp; &nbsp; {<br>

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LoadSuccess = LoadReport(tempFilename, connectionString, providerName);<br>

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ProcessReportParameters(connectionString, reportQueueRef);<br>

&nbsp; &nbsp; &nbsp; &nbsp; }<br>

&nbsp; &nbsp; &nbsp; &nbsp; finally<br>

&nbsp; &nbsp; &nbsp; &nbsp; {<br>

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //File.Delete(tempFilename);<br>

&nbsp; &nbsp; &nbsp; &nbsp; }<br>

&nbsp; &nbsp; }<br>

&nbsp; &nbsp; return LoadSuccess;<br>

}<br>

<br>

The LoadReport method referenced in the above method is as follows:<br>

<br>

public bool LoadReport(string fileName, string connectionString, string providerName)<br>

{<br>

&nbsp; &nbsp; bool LoadSuccess = false;<br>

&nbsp; &nbsp; _report = new ReportDocument();<br>

&nbsp; &nbsp; _report.Load(fileName);<br>

&nbsp; &nbsp; LoadSuccess = _report.IsLoaded;<br>

&nbsp; &nbsp; if (LoadSuccess)<br>

&nbsp; &nbsp; {<br>

&nbsp; &nbsp; &nbsp; &nbsp; if (_report.ParameterFields.Count > 0)<br>

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ProcessReportParametersBasedOnReportInfo();<br>

&nbsp; &nbsp; &nbsp; &nbsp; SetReportDataConnection(_report, connectionString, providerName);<br>

&nbsp; &nbsp; }<br>

&nbsp; &nbsp; return LoadSuccess;<br>

}<br>

<br>

And, what I guess is the crucial code, here is the SetReportDataConnection code:<br>

<br>

public void SetReportDataConnection(ReportDocument report, string connectionString, string providerName)<br>

{<br>

&nbsp; &nbsp; string Locn;<br>

&nbsp; &nbsp; if ((report != null) && (report.DataSourceConnections.Count > 0))<br>

&nbsp; &nbsp; {<br>

&nbsp; &nbsp; &nbsp; &nbsp; for (int count = 0; count < report.DataSourceConnections.Count; count++)<br>

&nbsp; &nbsp; &nbsp; &nbsp; {<br>

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; string dsnName = GetDSNName(connectionString, providerName);<br>

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ConnectionInfo connectionInfo = RetrieveConnectionInfoFromRegistry(dsnName);<br>

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Tables tables = report.Database.Tables;<br>

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; foreach(Table table in tables)<br>

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br>

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TableLogOnInfo tableLogonInfo = null;<br>

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tableLogonInfo = table.LogOnInfo;<br>

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tableLogonInfo.ConnectionInfo.ServerName = connectionInfo.ServerName;<br>

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tableLogonInfo.ConnectionInfo.DatabaseName = "";<br>

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tableLogonInfo.ConnectionInfo.UserID = connectionInfo.UserID;<br>

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tableLogonInfo.ConnectionInfo.Password = connectionInfo.Password;<br>

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; table.ApplyLogOnInfo(tableLogonInfo);<br>

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (connectionInfo.UserID.ToUpper().CompareTo("DBA".ToUpper()) != 0)<br>

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br>

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Locn = table.Location;<br>

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (!Locn.StartsWith("Proc(", StringComparison.OrdinalIgnoreCase))<br>

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br>

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if ((!Locn.StartsWith("DBA", StringComparison.OrdinalIgnoreCase))

&& (!Locn.StartsWith("SYS", StringComparison.OrdinalIgnoreCase)))<br>

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; table.Location = "DBA." + Locn;<br>

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; report.DataSourceConnections[count].SetConnection

(connectionInfo.ServerName, "", connectionInfo.UserID,

connectionInfo.Password);<br>

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>

&nbsp; &nbsp; &nbsp; &nbsp; }<br>

&nbsp; &nbsp; &nbsp; &nbsp; if (!report.IsSubreport)<br>

&nbsp; &nbsp; &nbsp; &nbsp; {<br>

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (report.Subreports.Count > 0)<br>

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br>

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for (int count = 0; count < report.Subreports.Count; count++)<br>

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br>

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SetReportDataConnection(report.Subreports[count], connectionString,

providerName);<br>

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>

&nbsp; &nbsp; &nbsp; &nbsp; }<br>

&nbsp; &nbsp; }<br>

If anyone has any idea why the ExportToStream call in the first causes the Exception, or can point me in the direction of where I am going wrong in setting the report's data connection, I'd really appreciate it.<br>

<br>

Thanks In Advance<br>

<br>

<br>p.s. - tried to format this as best I could, apologies if it is not all that clear

<br>

<br> Development language is C# Using Visual Studio .NET 2008

<br> Reports written in version 11 of Crystal Report.

Edited by: silentbazz on Jun 3, 2009 6:07 PM

Accepted Solutions (1)

Accepted Solutions (1)

former_member183750
Active Contributor
0 Kudos

You mention:

"Development language is C# Using Visual Studio .NET 2008

Reports written in version 11 of Crystal Report."

But what version is the CR runtime used in your .NET 2008 app? (e.g.; what is the version of the CR assemblies referenced in your app - say crystalDecisions.Crystalreports.engine.dll?)

Next, assuming you are using a version of CR supported with .NET 2008, I suppose the 1st question to ask is; is it export to stream, or is it incorrect db logon parameters that is causing the issue.

I'd recommend starting with the basics:

Simple app; viewer, load the report, let it do all the prompting. Does that work?

If yes, add the logon code to the above app, let it prompt for any parameter it needs. Does that work?

If yes, add the parameter code, does that work?

If all of the above works, try to export the report from the above app using the viewer export button. Does that work?

If that works, we're finally at the stage where we can point our finger at export to stream(?).

Ludek

Answers (0)