Search code examples
c#crystal-reportsvisual-studio-2019

Crystal Report doesn't open when I try to open it programmatically


I got a rpt file which executes a stored procedure from SQL Server. When I open it from Visual Studio 2019 with Main Report Preview and give it the parameter fields it opens with the correct values, when I try to open it programmatically, I get this error

The rowset column could not be found.

But when I place a breakpoint on the SetDatabaseLogon() and pass it with Step Over it opens. Also I noticed that I need to give it its Parameter Values before SetDatabaseLogon() for this to work. The issues seems to be the report attribute hasRecords when I pass over SetDatabaseLogon() with continue to another line hasRecords has an exception

report.HasRecord threw an exception of type CrystalDescision.CrystalReports.Engine.LogonException

but if I pass it with Step Over hasRecords is either true or false in which case my report opens as intended.

I tried adding Thread.Sleep() on different lines but without any success. Also the stored procedure works fine and it's fast, I have also tried to open it with the same parameter values I use when I verify database, another thing I tried is to open it without any parameter values in which case it did work.


Solution

  • I assume that your report is in an older version. Firstly you need to verify database in the older version using Crystal Reports. Also don't forget to check database location and remove the database name incase it's static and you should set Alias same as stored procedure name. After that you have to open it from VS2019 and verify it again. Problem solved.