I would like to extract the SQL queries from Crystal Report .rpt files, is there a way to do this?

前端 未结 6 2075
自闭症患者
自闭症患者 2021-02-05 12:40

I would like to extract the SQL queries from Crystal Report .rpt files, is there a way to do this?

I don\'t have any of the Crystal Reports products, just the .rpt files

6条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-05 13:02

    JoshL's answer worked for several of my reports, but not all of them. The following method, using ReportClientDocument.RowsetController.GetSQLStatement, was able to extract some of the queries that the other method missed.

    foreach (string file in Directory.GetFiles("c:\\projects\\Reports", "*.rpt"))
    {
        Console.WriteLine(String.Format("Processing {0}...", file));
        var doc = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
        doc.Load(file);
    
        var controller = doc.ReportClientDocument.RowsetController;
    
        var groupPath = new CrystalDecisions.ReportAppServer.DataDefModel.GroupPath();
        string temp = String.Empty;
        string commandSql = controller.GetSQLStatement(groupPath, out temp);
        //TODO: do something with commandSql
    }
    

提交回复
热议问题