cancel
Showing results for 
Search instead for 
Did you mean: 

Internal error exception when try to export Crystal Report using V2008 C#

Former Member
0 Kudos
1,305

Hello

Im working in an application that should send a parameter to a crystal report. Everything works fine when i test the report in the CR 2008 and shows the information correctly

After has the report working, i design a Visual C# application using forms and loading and exporting the report, which still works ok (generates the pdf file with the information)

Then i convert this application as a console application. The point is i need the report working as a windows service, to generate it every 15 minutes without user intervention (but try it as a console application first to be sure it will work ok before creating as a service)

Then i started the service. But when i call the report it sends an exception that i cannot understand:

Internal exception No se pudo abrir la conexion.

No se pudo abrir la conexion.

Prueba {DDE88B40-8A22-4EDB-9DEE-A5033DAA0140}.rpt

This is my code for the report that works fine as long as i don´t put any parameter into the sql command:

ReportDocument cryRpt = new ReportDocument();

cryRpt.Load(nomRepU);

cryRpt.Refresh();

cryRpt.SetParameterValue("EVAId", evaID);

//

ExportOptions CrExportOptions = new ExportOptions();

DiskFileDestinationOptions CrDiskFileDestinationOptions = new DiskFileDestinationOptions();

PdfRtfWordFormatOptions CrFormatTypeOptions = new PdfRtfWordFormatOptions();

CrDiskFileDestinationOptions.DiskFileName = @"" + path + "

" + nomRepPDF_Exp;

CrExportOptions = cryRpt.ExportOptions;

CrExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;

CrExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;

CrExportOptions.DestinationOptions = CrDiskFileDestinationOptions;

CrExportOptions.FormatOptions = CrFormatTypeOptions;

cryRpt.Export(); -

-


here i get the exception

I checked that the parameter is being read correctly in the crystal report as i remove all the sql commands and just put the parameter in the heading of the report, and is show as supposed and generates the pdf file automatically, but when i assign the parameter to the sql command (select * from myTable where idTable = {?EVAId} ) the crystal report send the exception i mentioned above

I don't know what to do, i don't know if i configuring correctly the report or something is missing. I would appreciate any help. If need more information please let me know. This is making me crazy

Thanks in advance

Veronica Estrada

Accepted Solutions (1)

Accepted Solutions (1)

0 Kudos

Hello,

What may be happening is the report can't find the database driver or DSN or client running as a service.

Add a try/catch to catch the actual error. Something like this but write it to a text file as message boxes won't work in a service.

Also add it to each function:

try{

cryRpt.Load(nomRepU);

}

catch (Exception ex)

{

MessageBox.Show("ERROR: " + ex.Message);

}

Thank you

Don

Former Member
0 Kudos

Hello Don

Thanks for answering, in fact i just added the try catch to several parts of the code to identify where exactly i'm getting the error and it occurs in the cryRpt.Export(); function, but only when i have in the crystal report a query that uses the received parameter in the sql command, for example: when i have in the report select * from myTable where IdTable = {?parameterFromApplication}

If i don´t use the parameterFromApplication in the sql command it works ok

Please let me know if you have any idea why this may happening, im working in Visual Studio C# 2008, CR 2008

By the way, this works perfectly if the application is not a windows service

Veronica Estrada

Edited by: vestrada07 on Dec 27, 2010 9:46 AM

Former Member
0 Kudos

Hello all

I just fixed my issue, i made some changes in the code as well as in the crystal report:

*Crystal report changes*

I removed the parameter that i have to filter the information, instead i in the C# code i let the crystal report which records to show

Note: in the preview of the report all information will be shown, however i won´t use it this way so is not a problem

*Visual C# changes*

// Load the crystal report

cryRpt.Load(nomRepU);

// --

// Establish SQL conection parameters - below the code for the function

SetTableLocation(cryRpt.Database.Tables);

// --

//This is really the main change, because if i use "setParameter" function still generates "Internal exception"

cryRpt.DataDefinition.RecordSelectionFormula = "{EVAPrincipal.EVAId} = " + evaId; // ---> Should be the same name of the table and the recordID i want to show

...

// Export function

cryRpt.Export();

private void SetTableLocation(Tables tables)

{

ConnectionInfo connectionInfo = new ConnectionInfo();

connectionInfo.ServerName = @"" + server; // ODBC

connectionInfo.DatabaseName = @"" + initialCatalog; // data base name

connectionInfo.UserID = @"" + user;

connectionInfo.Password = @"" + password;

foreach (CrystalDecisions.CrystalReports.Engine.Table table in tables)

{

TableLogOnInfo tableLogOnInfo = table.LogOnInfo;

tableLogOnInfo.ConnectionInfo = connectionInfo;

table.ApplyLogOnInfo(tableLogOnInfo);

}

}

My notes:

I guess i had two problems: the first with the SQL connection, in connectionInfo.ServerName i was using the name of the instance instead of the ODBC name. The second is the way the parameter is received in the crystal report as it works as windows service (this is my guess) then if i control everything through the C# code it runs perfect!

Hope this helps if anyone has a similar problem

Regards

Veronica Estrada

Answers (0)