1

I'm attempting to include a pre-created CrystalReport which links to a mysql database via a system DataSource (created by our designer) in our WPF application. However i've run into a roadblock, whenever the report is loaded in our application, it asks for database login, and fails to login even with valid information.

I have the following code:

            string path = System.IO.Path.Combine(Environment.CurrentDirectory, @"FrontPageReport.rpt");
            ReportDocument cryRpt = new ReportDocument();
            cryRpt.Load(path);
            ParameterFieldDefinitions crParameterFieldDefinitions;
            ParameterFieldDefinition crParameterFieldDefinition;
            ParameterValues crParameterValues = new ParameterValues();
            ParameterDiscreteValue crParameterDiscreteValue = new ParameterDiscreteValue();
            //System.Net.NetworkCredential networkCredentials = new System.Net.NetworkCredential("ShippingClient", "1234", "domain");
            cryRpt.SetDatabaseLogon("ShippingClient", "1234");

            crParameterDiscreteValue.Value = shipmentID;
            crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields;
            crParameterFieldDefinition = crParameterFieldDefinitions["shipment_id"];
            crParameterValues = crParameterFieldDefinition.CurrentValues;

            crParameterValues.Clear();
            crParameterValues.Add(crParameterDiscreteValue);
            crParameterFieldDefinition.ApplyCurrentValues(crParameterValues);

            FrontPageReport.ViewerCore.ReportSource = cryRpt;

I have created a datasource which mirrors that of the CrystalReport using ODBC DataSource Administrator tool. However I still get the login popup that always fails.

Can anyone assist?

EDIT:

Turns out is has nothing to do with subreports infact it seems totally random which reports work and dont work, all using the dame database, same tables, same datasource, same login.

If i open the report in Visual Studio and click "Main Report Preview" i enter a valid paramter and it works like a charm, so why wont it work when the application is loaded?

Am i missing something major here?

2 Answers 2

0

Ok i have a solution to this, it is not the ideal solution in my mind, but it works. Basically you have to replace the datasource of the report with a data table in visual studio, and then manually fill that datatable.

You create a dataset, and inside that a datatable. Then add columns to that datatable that represent the data returned for the report (so the columns returned from the select statement for example)

then you use something like the following code. Bear in mind this is using mysql, but the process wont change much for sql servers.

ReportDocument cryRpt = new ReportDocument();
            MySqlConnection cn = new MySqlConnection("Server=IPADDRESS;Uid=USERNAME;Pwd=PASSWORD;Database=DATABASENAME;");
            //This is where you run the sql to select, as you can see, we're using a procedure
            MySqlDataAdapter da = new MySqlDataAdapter("CALL letter_head_address()", cn);
            DataSet ds = new DataSet();
            //This is where you fill the data table, the second parameter is the name of the data table you previously created.
            da.Fill(ds, "my_dt");
            cryRpt.Load(path);
            cryRpt.DataSourceConnections.Clear();
            cryRpt.SetDataSource(ds);

Hopefully this will help someone else along the road, and i continue to look at why the original issue happened.

0

My problem was fixed by changing the app.config file from:

<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup>

to:

<startup useLegacyV2RuntimeActivationPolicy="true"><supportedRuntime version="v4.0"/></startup>

as obtained from post: https://social.msdn.microsoft.com/Forums/vstudio/en-US/fc4640ed-72ac-4e02-be68-6fe9760c50f8/could-not-load-file-or-assembly-filecprogram-files-x86sap-businessobjectscrystal-reports?forum=csharpgeneral&prof=required

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.