Writing Code
 Crystal Reports Forum : Crystal Reports for Visual Studio 2005 and Newer : Writing Code
Message Icon Topic: LogOnException thrown when calling ExportToStream Post Reply Post New Topic
Author Message
silentbazz
Newbie
Newbie


Joined: 03 Jun 2009
Online Status: Offline
Posts: 1
Quote silentbazz Replybullet Topic: LogOnException thrown when calling ExportToStream
    Posted: 03 Jun 2009 at 8:02am
Hi there,
 
I am having real problems when calling the ExportToStream method on the ReportDocument class.
 
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.
 
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:\DOCUME~1\BARRY~1.ROB\LOCALS~1\Temp\tmp16C {8CF0E4A7-E74C-41DC-BF7E-5871D40432E9}.rpt:
Unable to connect: incorrect log on parameters.").
 
The code causing the excpetion is the call to ExportToStream below:

public void ProcessQueuedReports(string connectionString, ProcessQueueMode processMode, string providerName)

{ 

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

  if (queuedReportList.Count > 0){
    int numberToProcess = ReturnNumberToProcess(processMode,
      queuedReportList.Count);
  for (int count = 0; count < numberToProcess; count++)
  {
    SetQueueItemAsProcessing(queuedReportList[count]);
    if (reportReader.LoadReport(connectionString,
        queuedReportList[count].ReportDetailsRef,
        queuedReportList[count].ReportQueueDetailsRef, providerName))
    {
      ExportFormatType outputFormat =
        ReturnExportFormatType(queuedReportList[count].ReportFormatTypeCode);
      Stream reportStream = new MemoryStream();
      reportReader.Report.ReportOptions.EnableSaveDataWithReport = false;
      reportStream = reportReader.Report.ExportToStream(outputFormat);
      byte[] reportData = new byte[(int)reportStream.Length];
      int numBytesToRead = (int)reportStream.Length;
      int numBytesRead = 0;
      reportStream.Position = 0;
      while (numBytesToRead > 0)
      {
        int n = reportStream.Read(reportData, numBytesRead, numBytesToRead);
        if (n == 0)
          break;
        numBytesRead += n;
        numBytesToRead -= n;
      }
      queuedReportList[count].ReportOutput = reportData;
      queuedReportList[count].Update(IyssDateTime.CurrentDatabaseDateTime);
      SetQueueItemAsSuccess(queuedReportList[count]);
    }
   else
   {
      SetQueueItemAsFailed(queuedReportList[count]);
   }
  }
 }
}
 
This is the LoadReport method called above:
 

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

{

  bool LoadSuccess = false;
  ReportDetails report = IyssReportDetails.GetByRef(reportDetailsRef,
    connectionString);
  byte[] reportData = (byte[])report.ReportData;
  int size = reportData.GetUpperBound(0);
  string tempFilename = Path.GetTempFileName();
  if (tempFilename != "")
  {
    FileStream fs = new FileStream(tempFilename, FileMode.OpenOrCreate,
      FileAccess.Write);
    fs.Write(reportData, 0, size);
    fs.Close();
    try
    {
      LoadSuccess = LoadReport(tempFilename, connectionString, providerName);
      ProcessReportParameters(connectionString, reportQueueRef);
    }
    finally
    {
      //File.Delete(tempFilename);
    }
  }
  return LoadSuccess;
}
 
 
The LoadReport method referenced in the above method is as follows:
 

public bool LoadReport(string fileName, string connectionString, string providerName)

{

  bool LoadSuccess = false;
  _report = new ReportDocument();
  _report.Load(fileName);
  LoadSuccess = _report.IsLoaded;
  if (LoadSuccess)
  {
    if (_report.ParameterFields.Count > 0)
      ProcessReportParametersBasedOnReportInfo();
    SetReportDataConnection(_report, connectionString, providerName);
  }
  return LoadSuccess;
}
 
And, what I guess is the crucial code, here is the SetReportDataConnection code:
 

public void SetReportDataConnection(ReportDocument report, string connectionString, string providerName)

{

  string Locn;
  if ((report != null) && (report.DataSourceConnections.Count > 0))
  {
    for (int count = 0; count < report.DataSourceConnections.Count; count++)
    {
      string dsnName = GetDSNName(connectionString, providerName);
      ConnectionInfo connectionInfo = RetrieveConnectionInfoFromRegistry(dsnName);
      Tables tables = report.Database.Tables;
      foreach(Table table in tables)
      {
        TableLogOnInfo tableLogonInfo = null;
        tableLogonInfo = table.LogOnInfo;
        tableLogonInfo.ConnectionInfo.ServerName = connectionInfo.ServerName;
        tableLogonInfo.ConnectionInfo.DatabaseName = "";
        tableLogonInfo.ConnectionInfo.UserID = connectionInfo.UserID;
        tableLogonInfo.ConnectionInfo.Password = connectionInfo.Password;
        table.ApplyLogOnInfo(tableLogonInfo);
        if (connectionInfo.UserID.ToUpper().CompareTo("DBA".ToUpper()) != 0)
        {
          Locn = table.Location;
          if (!Locn.StartsWith("Proc(", StringComparison.OrdinalIgnoreCase))
          {
            if ((!Locn.StartsWith("DBA", StringComparison.OrdinalIgnoreCase))
             && (!Locn.StartsWith("SYS", StringComparison.OrdinalIgnoreCase)))
              table.Location = "DBA." + Locn;
          }
        }
      }
      report.DataSourceConnections[count].SetConnection
       (connectionInfo.ServerName, "", connectionInfo.UserID,
        connectionInfo.Password);
     }
    }
   if (!report.IsSubreport)
   {
    if (report.Subreports.Count > 0)
    {
     for (int count = 0; count < report.Subreports.Count; count++)
     {
       SetReportDataConnection(report.Subreports[count], connectionString,
         providerName);
     }
    }
   }
  }
 
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.
 
Thanks In Advance
IP IP Logged
Post Reply Post New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum



This page was generated in 0.047 seconds.