on 12-13-2012 2:33 PM
public void RunReport(string outputFile, int cc, int yr, int wk)
{
ReportDocument rd = new ReportDocument();
rd.Load(FullFilePath("myreport.rpt"));
rd.Refresh();
rd.SetDatabaseLogon("userid", "password");
foreach (Table tbl in rd.Database.Tables)
{
tbl.LogOnInfo.ConnectionInfo.ServerName = "dbname";
tbl.LogOnInfo.ConnectionInfo.DatabaseName = "";
tbl.LogOnInfo.ConnectionInfo.UserID = "userid";
tbl.LogOnInfo.ConnectionInfo.Password = "password";
}
foreach (IConnectionInfo ci in rd.DataSourceConnections)
{
ci.SetLogon("userid", "password");
}
DiskFileDestinationOptions CrDiskFileDestinationOptions = new DiskFileDestinationOptions();
ExportOptions CrExportOptions;
PdfRtfWordFormatOptions pdfFormatOptions = new PdfRtfWordFormatOptions();
CrDiskFileDestinationOptions.DiskFileName = outputFile;
CrExportOptions = rd.ExportOptions;
{
CrExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
CrExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
CrExportOptions.DestinationOptions = CrDiskFileDestinationOptions;
CrExportOptions.FormatOptions = pdfFormatOptions;
}
SetCurrentValuesForParameterField(rd, "IP_COMP_CODE", cc);
SetCurrentValuesForParameterField(rd, "IP_YEAR", yr);
SetCurrentValuesForParameterField(rd, "IP_WEEK", wk);
rd.Export();
}
Obviously I've changed the names of the userid, password, database and report.
So, as I said, the first time I do the export it fails. If I ignore the exception and run the export again, it'll work just fine and it'll continue to work fine. I can run reports until I stop the app (an ASP.NET MVC application)
I've tried different formats as well, specifically, CSV and XLS. No matter which I do first, I'll get the out of memory the first time I export and then it'll work fine. So, for example, I could export as PDF, it will fail, and then export in XLS and it'll work. If I do XLS first, it'll fail, but then whatever I do after will work fine. So the problem doesn't appear to be specific to the export format.
I am using CRforVS_redist_install_64bit_13_0_4.zip
I'm running Windows 7 64-bit.
Thanks for any insight you can provide.
Sorry, it looks like the beginning of my post got out of order somehow. Should begin like this:
I have a report I'm exporting to PDF. In an initial trial a month ago, I got it working and it seemed to work fine. I moved the code over to my main app, and now I'm getting an out of memory error the first time I run the export. Specifically, the first time I run the export, I get this in my debug output:
First-chance exception at 0x75a2c41f in w3wp.exe: Microsoft C++ exception: _com_error at memory location 0x20dee4b0.
A first chance exception of type 'System.Runtime.InteropServices.COMException' occurred in CrystalDecisions.CrystalReports.Engine.dll
An exception of type 'System.Runtime.InteropServices.COMException' occurred in CrystalDecisions.CrystalReports.Engine.dll but was not handled in user code
Additional information: Memory full.
Failed to export the report.
And then it's correct after that. Sorry.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Forgot this method that is called from the code above:
private void SetCurrentValuesForParameterField(ReportDocument reportDocument, string paramFieldName, int value)
{
ParameterDiscreteValue parameterDiscreteValue = new ParameterDiscreteValue();
parameterDiscreteValue.Value = value.ToString();
ParameterValues currentParameterValues = new ParameterValues();
currentParameterValues.Add(parameterDiscreteValue);
reportDocument.DataDefinition.ParameterFields[paramFieldName].ApplyCurrentValues(currentParameterValues);
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Peter
See if the following will help;
remove
rd.Refresh();
Instead of SetLogon use ApplyLogon.
SetLogon will only log on to the original datasource, ApplyLogon will allow you to also change to a different datasource making the app a bit more "extensible"(?). here is a code snippet that should help:
// Load Report
.
.
.
//ApplyLogon
CrConnectionInfo = New ConnectionInfo
With crConnectionInfo
.ServerName = "dbconn1"
.DatabaseName = "Pubs"
.UserID = "vantech"
.Password = "vantech"
crDatabase = crReportDocument.Database
crTables = crDatabase.Tables
End With
crDatabase = crReportDocument.Database
crTables = crDatabase.Tables
For Each crTable In crTables
crTableLogOnInfo = crTable.LogOnInfo
crTableLogOnInfo.ConnectionInfo = crConnectionInfo
crTable.ApplyLogOnInfo(crTableLogOnInfo)
Next
Sorry - just realized you're using C#, but the conversion should be easy enough. Or see the sample
csharp_win_paramengine.zip here:
http://wiki.sdn.sap.com/wiki/x/JQBmBQ |
- Ludek
Follow us on Twitter
Got Enhancement ideas? Try the SAP Idea Place
Ludek,
Thanks for the response. When I make those changes, I get this exception on the rd.Export()
An exception of type 'CrystalDecisions.CrystalReports.Engine.DataSourceException' occurred in CrystalDecisions.ReportAppServer.DataSetConversion.dll but was not handled in user code
Additional information: Failed to load database information.
Error in File e00721cc2008213a {6DC42165-A38A-4CB2-85FD-A77389827FA9}.rpt:
Failed to load database information.
That is actually why I added the rd.Refresh() call to begin with.
My code now looks like this (just showing the area that changed):
ReportDocument rd = new ReportDocument();
rd.Load(FullFilePath("myreport.rpt"));
ConnectionInfo connectInfo = new ConnectionInfo()
{
ServerName = "dbname",
DatabaseName = "",
UserID = "userid",
Password = "password"
};
rd.SetDatabaseLogon("userid", "password");
foreach (Table tbl in rd.Database.Tables)
{
tbl.LogOnInfo.ConnectionInfo = connectInfo;
tbl.ApplyLogOnInfo(tbl.LogOnInfo);
}
I have removed the SetLogon stuff.
Hmmm, "Failed to load database information" error usuall means there is a something wrong on the database side. Permissions. 32 bit ODBC when we need 64 ODBC, etc.,etc. Please enter the search terms 'failed database information crystal' into the search box at the top right corner of this web page. There will be a few Kbs that may point you in the right direction.
- Ludek
I've been through about 20 posts with that search string. I've found nothing that seems to apply to my situation.
I'm a little confused. It worked perfectly fine after the first out of memory exception, with my original code. I use that database for my entire application. I've had no issues.
It's not an ODBC issue because I'm not using ODBC. And if it were an permission issue, it wouldn't work after the first Out Of Memory exception with my original code.
And what's even more disturbing is I reverted the changes and went back to my original code, but I continue to get the Failed to load database information.issue and now it's totally broken.
Well, things are just going from bad to worse. I uninstalled Oracle and uninstalled Crystal and then reinstalled each with reboots in between.
Oracle works just fine. Crystal is now failing on Creating the Report Document:
ReportDocument rd = new ReportDocument();
The exception is:
A first chance exception of type 'System.IO.FileNotFoundException' occurred in GEMS.Web.dll
Additional information: Could not load file or assembly 'CrystalDecisions.ReportAppServer.ClientDoc, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304' or one of its dependencies. The system cannot find the file specified.
Which is interesting because that DLL is clearly in the GAC.
As I mentioned before, my app is ASP.NET. Just in case you're wondering, I do have Enabled 32-bit Applications set to true.
Our company is about to rewrite our primary enterprise application and we're trying to test the various components that the system will require. This project has just begun and the version of VS.NET we have is 2012.
One of those components we're trying to test is reporting. Our company is currently licensing Crystal and we have knowledge in that area. However, I have just a few more days before I have to make a decision about whether we stick with Crystal or switch to SSRS.
Frankly, the version of VS.NET shouldn't matter for what I'm trying to do because I'm not using any of the pieces that integrate with VS.NET. I'm simply trying to use your SDK and I'm perfectly willing to use an earlier version of the .NET SDK to achieve that.
But if you're telling me that I can't get support for this issue until you guys release your VS 2012 version, then I don't see that I have much choice but to tell my boss we need to switch to SSRS because I can't wait that long to verify the functionality.
Sorry Peter. But apparently this does not apply:
Frankly, the version of VS.NET shouldn't matter for what I'm trying to do because I'm not using any of the pieces that integrate with VS.NET.
E.g.; it's not working in VS 2012. I know it is working in VS 2010...
Not much I can do, irrespective of you choosing to go to SSRS.
Regards,
- Ludek
User | Count |
---|---|
86 | |
10 | |
10 | |
9 | |
6 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.