mikey
mikey

Reputation: 31

CrystalReports error from within a service. (Failed to load database information.)

I have numerous reports that previously pulled data from an ODBC source in a legacy desktop application. I am now trying to populate these reports within a C# .net service by loading data into a DataTable.

The code runs fine in a windows application, but not the service.

I have tried compiling as both x86 and x64 for the service, as well as running the service as the same user that is being used to run the desktop application.

Snippet:

ReportDocument rd = new ReportDocument();

StreamReader sr = new StreamReader(@"C:\infile.txt");

DataTable dt = new DataTable("REPORTTABLE");

string[] columnNames = new string[3];

columnNames[0] = "COL1";
columnNames[1] = "COL2";
columnNames[2] = "COL3";

foreach (string colName in columnNames)
{
   dt.Columns.Add(colName);
}

int i = 0;

DataRow dr;
string[] fields = new string[3];

while (!sr.EndOfStream)
{
   fields[i] = sr.ReadLine();
   i++;
}
dt.Rows.Add(fields);
sr.Close();

rd.Load(@"C:\report.rpt");
rd.SetDataSource(dt);

The exception is thrown at SetDataSource(). The column names and data table name is the same as what had been verified against the ODBC data source previously. The input data is a line per column in a text file e.g.

data1 data2 data3

The initial error is:

Error in File marriage 18884_5280_{F58B98C0-1D10-462C-98F8-88974D74BFF8}.rpt:
Failed to load database information.

Stack trace:

   at CrystalDecisions.ReportAppServer.ConvertDotNetToErom.ThrowDotNetException(Exception e)
   at CrystalDecisions.CrystalReports.Engine.ReportDocument.SetDataSourceInternal(Object val, Type type)
   at CrystalDecisions.CrystalReports.Engine.ReportDocument.SetDataSource(DataSet dataSet)
   at WindowsService1.Service1.OnTimer(Object sender, ElapsedEventArgs args) in C:\Users\himik\source\repos\WindowsService1\WindowsService1\Service1.cs:line 432

Thank you in advance.

Upvotes: 1

Views: 2619

Answers (1)

mikey
mikey

Reputation: 31

Alright, after firing up Process Explorer I found the solution. Despite testing targets of either x86 and x64 and it making no difference, I found that with Crystal it still chooses the x86 libraries if you choose the option "Prefer 32-bit" in the Build properties of the project. Un checking this option means that the correct library for the environment (x64 in my case) were used and the report runs correctly.

Upvotes: 1

Related Questions