5

I need to retrieve the name of the stored procedure that a crystal report is running. Is there any way to do this in C# using the CrystalDecisions.CrystalReports.Engine.ReportDocument object?

I can't seem to find a property that will give me the stored procedure name.

Is this even possible? I've been through almost all the properties I can think of. The DataDefinition object has collections for the Formula, Parameter, Group Name, and Running Total Fields, but not one for the Database Fields.

Edit: I need to do this programatically, as I have a lot of reports. I need the option of skipping the actual running of the report and just executing the stored procedure that the report would have used. So when the report information is inserted into the database using the program, I want to be able to pull out its stored procedure and store that information separately.

Brandon
  • 68,708
  • 30
  • 194
  • 223
  • Like just once or programatically? If it's just once I suggest you attach the sql profiler to the database in question, invoke the report and see what it does. – Klaus Byskov Pedersen Mar 25 '10 at 17:41
  • Programatically. We actually have a few hundred reports, but some users want the option to just run the stored procedure directly, and have the results exported to a CSV file. This works for almost all reports, because we have a standard naming practice for stored procedures, but there are a few odd cases. Rather than having to maintain a list, I'd rather just be able to pull it out of the report itself and put it in the database somewhere. – Brandon Mar 25 '10 at 18:06

4 Answers4

4

You're going to kick yourself. The SP's are in...

ReportDocument.Database.Tables

DataBase

then Table.Location

Table

also don't forget about SubReports...which is another collection of ReportDocuments.

dotjoe
  • 26,242
  • 5
  • 63
  • 77
  • Thank you so much. You just saved me a lot of work, and I am kicking myself for not checking the Table object :P – Brandon Mar 26 '10 at 22:27
1

You can use SQLServer Profiler to capture what stored procedure is being called when you run the crystal report.

First, you need to have the right privileges to run profiler.
Second, you need to start trace and immediately execute the report.
Third, stop the trace & scan to see the name of the stored procedure(s) the report executed.

SoftwareGeek
  • 15,234
  • 19
  • 61
  • 78
  • Thanks for the answer, but I actually need to do this programatically. – Brandon Mar 25 '10 at 22:55
  • Could you try opening the report itself in an editor like wordpad or xmlnotepad? Maybe that could have some metadata that you can search for the sproc. – SoftwareGeek Mar 26 '10 at 18:13
0

You can output the various properties of a Table with this code (sorry it's in VB, that's what I have to use for this project):

Private Sub logLogOnInfo(table As Table) log.DebugFormat("LogOnInfo.ConnectionInfo for {0}:", table.Name) Dim ci As ConnectionInfo = table.LogOnInfo.ConnectionInfo log.Debug(String.Format("AllowCustomConnection: {0}, DBName: {1}, IntegratedSecurity: {2}", ci.AllowCustomConnection, ci.DatabaseName, ci.IntegratedSecurity)) log.Debug(String.Format("ServerName: {0}, User: {2}, Password: {1}, Attributes:", ci.ServerName, ci.Password, ci.UserID))

For Each a As NameValuePair2 In ci.Attributes.Collection
    If a.Name = "QE_LogonProperties" Then
        Dim attributes As DbConnectionAttributes = a.Value
        For Each b As NameValuePair2 In attributes.Collection
            log.DebugFormat("        {0}: {1}", b.Name, b.Value)
        Next
    Else
        log.DebugFormat("    {0}: {1}", a.Name, a.Value)
    End If
Next

End Sub

Michael
  • 1,351
  • 1
  • 11
  • 25
0

Give this project a try: RptToXml.

craig
  • 25,664
  • 27
  • 119
  • 205