R – Problems converting crystal reports from vb6 standalone app to .net web app

crystal-reportsnet

I have been asked to convert a legacy app containing some crystal reports from vb6 standalone to .net c# web based application

This is my first .net c# web app so I am learning as I go

My attempts to get crystal reports .net (included version not licensed) have failed.

I was pleasantly surprised to find that I could simply copy the .rpt files into visual studio 2008 and they worked… well almost

opening the .rpt file works fine in the ide, I can view the report and its populated correctly

On the other hand if I try to edit the report from the smart tag in the crystalreportsource (on the aspx page) fails with "report source not configured" even though it is.

at runtime I get the error "report failed to load"

I also need to connect to a SQL database using one of the connection strings provided in web.config this connection string can be changed at runtime (to a training db)

I searched and found several techniques for changing the connection string but any attempt to change the connection properties at runtime fails.

So I was wondering if there are any gotcha's that I need to know about?

Am I doomed to failure?

If necessary is there an easy way to convert to Microsofts reportviewer?

DC (aka dazed and confused)

RESOLVED: fails with "report source not configured"

The problem appears that a reference wasn't loaded or was loaded incorrectly I re-added the crystal reports references which immediately crashed VS2008 once restarted I loaded them again and the error disappeared.

DC

Best Answer

Ok Problems solved. Not ideally but solved any way.

I have put this here so others may learn from my struggle.

Crystal reports (v9 included with vs2008) won't use a SQL (or any other connection) it must use either a dataset or an ODBC connection. As I don't know much about datasets, so I didnt take this path.

Crystal reports seems to be designed to use the designer you cannot create it it dynamically. and this is reflected in how hard it is to alter the connection. everything failed until I found this How do I change a Crystal Report's ODBC database connection at runtime? patm's solution was the one which provided the clues.

this is my solution c# implemented in the page_load method

        SqlConnectionStringBuilder SConn = new SqlConnectionStringBuilder(_connectionString);

        ReportDocument cryRpt = new ReportDocument();
        TableLogOnInfos crtableLogoninfos = new TableLogOnInfos();
        TableLogOnInfo crtableLogoninfo = new TableLogOnInfo();
        ConnectionInfo crConnectionInfo = new ConnectionInfo();
        crConnectionInfo.ServerName = dsn;// SConn.DataSource;
        crConnectionInfo.DatabaseName = SConn.InitialCatalog;
        crConnectionInfo.UserID = SConn.UserID;
        crConnectionInfo.Password = SConn.Password;

        String rpt = Server.MapPath(@"~/reports2/Report1.rpt");
        cryRpt.Load(rpt);
        foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in cryRpt.Database.Tables)
        {
            crtableLogoninfo = CrTable.LogOnInfo;
            crtableLogoninfo.ConnectionInfo = crConnectionInfo;
            CrTable.ApplyLogOnInfo(crtableLogoninfo);
        }

        CrystalReportViewer1.ReportSource = cryRpt;
        CrystalReportViewer1.RefreshReport();

dsn is the name of the ODBC connection NOT the server you want to connect to eg. NOT "localhost/sqlexpress"

I tried many different ways of setting a connection to the database dynamically and only the above worked. my guess is that the others required a fully licensed version of Crystal Reports although none stated it.

DC

Related Topic