cancel
Showing results for 
Search instead for 
Did you mean: 

How to change data source for a ttx-report in WPF-application

Former Member
0 Kudos

Hello.

I have a *.rpt-file, created in the "SAP Crystal Reports" program with a ttx-file as data source description.

For example, the .ttx file is very simple:


str1    String    25    test1

I need show this report by a WPF-application, and I want to use an "Object Collection" for filling its data.

I try chahge a data source for the report like this:

namespace WPFTest
{
    public class Filds3
    {
        public string str1 { get; set; }
    }

    public partial class MainWindow : Window
    {
        public CrystalReportsViewer crystalReportsViewer1;

        public MainWindow()
        {
            InitializeComponent();
            try
            {
                this.crystalReportsViewer1 = new CrystalReportsViewer()
                {
                    Height = 500,
                    Width = 800
                };
                
                ReportDocument doc = new ReportDocument();
                doc.Load("Report4.rpt");

                var testValues2 = new ArrayList()
                {
                    new Filds3 { str1 = "sd133" },
                    new Filds3 { str1 = "sd222" },
                    new Filds3 { str1 = "sd344" },
                    new Filds3 { str1 = "sd4323" },
                };

                string modelClassName = "WPFTest.Filds3";

                NameValuePairs2 connectionProperties = new NameValuePairs2
                    {
                        new NameValuePair2
                        {
                            Name = DbConnectionAttributes.CONNINFO_DATABASE_DLL,
                            Value = DbConnectionAttributes.DATABASE_DLL_CRDB_ADOPLUS
                        },
                        new NameValuePair2
                        {
                            Name = DbConnectionAttributes.QE_DATABASE_NAME,
                            Value = ""
                        },
                        new NameValuePair2
                        {
                            Name = "QE_DatabaseType",
                            Value = "ADO.NET (XML)"
                        },
                        new NameValuePair2
                        {
                            Name = DbConnectionAttributes.QE_SERVER_DESCRIPTION,
                            Value = modelClassName
                        },
                        new NameValuePair2
                        {
                            Name = "QE_SQLDB",
                            Value = false
                        },
                        new NameValuePair2
                        {
                            Name = "SSO ENABLED",
                            Value = false
                        },
                    };

                NameValuePairs2 logonProperties = new NameValuePairs2
                {
                    new NameValuePair2
                    {
                        Name = "ClassName",
                        Value = modelClassName
                    },
                    new NameValuePair2
                    {
                        Name = "Internal Connection ID",
                        Value = Guid.NewGuid().ToString()
                    }
                };

                foreach (CrystalDecisions.Shared.IConnectionInfo connection in doc.DataSourceConnections)
                {
                    connection.SetLogonProperties(logonProperties);
                }

                foreach (CrystalDecisions.CrystalReports.Engine.Table table in doc.Database.Tables)
                {
                    //TableLogOnInfo info = table.LogOnInfo;
                    TableLogOnInfo newInfo = new TableLogOnInfo();
                    newInfo.TableName = modelClassName;

                    DbConnectionAttributes newAttributes = new DbConnectionAttributes();

                    newAttributes.Collection = connectionProperties;

                    newInfo.ConnectionInfo.Attributes = newAttributes;
                    newInfo.ConnectionInfo.LogonProperties = logonProperties;

                    newInfo.ConnectionInfo.ServerName = modelClassName;
                    newInfo.ConnectionInfo.Type = ConnectionInfoType.CRQE;
                    newInfo.ConnectionInfo.UType = 5;

                    table.ApplyLogOnInfo(newInfo);                  

                    string location = table.Location;
                    table.SetDataSource(testValues2);

                   // table.Location = "WPFTest_Filds3"; // Exception here
                }

                this.crystalReportsViewer1.ViewerCore.ReportSource = doc;

                this.crystalReportsViewer1.Owner = this;

                this.Grid1.Children.Add(this.crystalReportsViewer1);

            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }
}
}

But I getting an Exception like:


Failed to load database information.

Error in File Report4 10384_8240_{4CDE0A62-05A9-4CBA-8A41-B185B3A3946A}.rpt:

Failed to load database information.

Tell me please, how I can correct my code for success.

Thank you.

Accepted Solutions (1)

Accepted Solutions (1)

former_member183750
Active Contributor
0 Kudos

Hi Gennady

Do not use ttx based reports. Ttx connection was retired like 10+ years ago... However, there is a solution. See KBA 1461779 - Error "Failed to save document" when running reports based on multiple TTX files in Visual...

- Ludek

Senior Support Engineer AGS Product Support, Global Support Center Canada

Follow me on Twitter

Former Member
0 Kudos

Hi Ludek

I have seen the post "How to use reports based on multiple TTX files in Visual Studio .NET " but the code from there can not be used now, for example, the reportClientDoc.DatabaseController.SetTableLocation(oldTable, myTable) function do not exist any longer and the code from there changes data source not to the object collection but to the ODBC connection to database.

Is it possible to change the ttx-data source to the Object Collection? If it is not, tell me please the solution for the next process:

1. Create a Crystal Report report without the Visual Studio and without any database connections

2. And I need an application which fills report with data and shows the report to user.

former_member183750
Active Contributor
0 Kudos

There is no other solution. But in a nutshell, all you need to do is create a dataset that matches precisely the format of the ttx file. Then you have to convert the driver to crdb_adoplus.dll.

Don't understand what you mean by:

the reportClientDoc.DatabaseController.SetTableLocation(oldTable, myTable) function do not exist any longer and the code from there changes data source not to the object collection but to the ODBC connection to database.

There have been no changes to the APIs since that doc was written. Perhaps a description of the actual issue may be a good idea(?).

- Ludek

Former Member
0 Kudos

Hi Ludek, thank you for replies.

The actual issue is that I can not use the code from the post "How to use reports based on multiple TTX files in Visual Studio .NET" in my WPF-application.

There are several problems:

1. The code from the post changes data source to the database connection but I need the "object collection" as a data source - I want to know which structures should I use and how to initialize it. 2. I use the "SAP Crystal Reports .NET SDK Developer Guide" and the "CrystalDecisions.CrystalReports.Engine.dll" module (and other, which available after the "CRforVS_13_0_14" package installation). And they have no "SetTableLocation" function (and other) from your example.

For example I found the ISCRDatabase interface with some functions from your example, but when I try to use it like:

ReportDocument doc = new ReportDocument(); 
doc.Load("Report3.rpt"); 
foreach (ISCRDatabase table in doc.ReportClientDocument.DatabaseController.Database.Tables) 
{ 
//... 
} 

I get the runtime exception:

Unable to cast COM object of type 'System.__ComObject' to interface type 'CrystalDecisions.ReportAppServer.DataDefModel.ISCRDatabase'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{86ACA0B3-3E06-11D3-9169-00902741EE7C}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

So I can not use your exaple from that post.

Please let me know how I can create new "object collection" data source for a ttx-report.

richard_weitkunat44
Discoverer
0 Kudos

We have old TTX reports with subreports whose fields are linked to the main reports fields, so we normally do not set a datasource for the subreports. How do I convert the datasource of the subreports in this case? Thanks

Answers (0)