Skip to Content
0

How to change data povider programmatically using .net

Jun 28, 2017 at 06:47 PM

138

avatar image
Former Member

We would like to programmatically change the data provider used by a report. Currently we are using ODBC and we no longer want to depend on the this middleware. Is possible to programmatically change the objects within the report's report document object to use a direct data connection or OLE DB connection? We would rather not change them through Crystal Report's designer if possible due to the number of reports that we would have to change.

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

5 Answers

Best Answer
Don Williams
Jul 05, 2017 at 09:43 PM
0

CR 2008 runtime is not supported in VS 2010 or above.

To get the runtime for CR 2011 and above go here:

https://wiki.scn.sap.com/wiki/display/BOBJ/Crystal+Reports%2C+Developer+for+Visual+Studio+Downloads

Update all references to version 13.

On the WIKI page there is a demo app for setting log on info and using RAS and ReplaceConnection();

Don

Show 3 Share
10 |10000 characters needed characters left characters exceeded
Former Member

Thanks everyone for the additional information. Would "ReplaceConnection oracle" and "ReplaceConnection sql server" be goods ways to search for how the replaceconnection method is used?

0
Former Member

The CR2011 runtime has been installed. and my application has version13.0.2000, runtime version 2.05727.

There is no example on the wiki that I can find. Please provide the exact url to it. Then I send it that url to the help desk where I work and they can scan it for viruses, etc. I am not allowed to download code directly to my workstation without permission.

0
Former Member

Hi Don, OK.

Couple of questions.

1) How do I close all of these other threads that I have opened so that there is just one thread of conversation (this one) ?

2) What is in the "Installation Package for Visual Studio IDE" ?

3) Will I be able to programmatically change my database provider type with this installation?

4) Does it require licensing for installation? If so our legal department will need to review the contract prior to the download.

Thank you

0
Dell Stinnett-Christy Jun 29, 2017 at 01:16 PM
0

Here's some C# sample code to get you started. You'll probably have to tweak this, though.

    private void updateLogon(ReportDocument newRpt, string alias)
    {
      for (int i = 1; i <= newRpt.Database.Tables.Count; i++)
      {
        ConnectionInfo cInfo = newRpt.Database.Tables[i].LogOnInfo.ConnectionInfo;
        cInfo.AllowCustomConnection = true;
        cInfo.ServerName = alias;
        cInfo.UserID = _rptUser;
        cInfo.Password = _rptPW;
        newRpt.Database.Tables[i].Location = _rptPrefix + "." + newRpt.Database.Tables[i].Name;
      }
      ///TODO: finish setting this up
        //if necessary, set the database driver
        if (_updateDriver && (_dbDriver != DBDrivers.SQL_Server))
        {
          switch (_dbDriver)
          {
            case DBDrivers.Oracle:
              newRpt.ReportLogons[j].CustomServerType = CeReportServerType.ceServerTypeOracle;
              break;
            case DBDrivers.DB2:
              newRpt.ReportLogons[j].CustomServerType = CeReportServerType.ceServerTypeDB2;
              break;
            case DBDrivers.ADO:
              newRpt.ReportLogons[j].CustomServerType = CeReportServerType.ceServerTypeUserSpecified;
              newRpt.ReportLogons[j].CustomDatabaseDLLName = "crdb_ado.dll";
              break;
            case DBDrivers.BTrieve:
              newRpt.ReportLogons[j].CustomServerType = CeReportServerType.ceServerTypeUserSpecified;
              newRpt.ReportLogons[j].CustomDatabaseDLLName = "crdb_p2bbtrv.dll";
              break;
            case DBDrivers.ODBC:
              newRpt.ReportLogons[j].CustomServerType = CeReportServerType.ceServerTypeUserSpecified;
              newRpt.ReportLogons[j].CustomDatabaseDLLName = "crdb_odbc.dll";
              break;
            case DBDrivers.OLAP:
              newRpt.ReportLogons[j].CustomServerType = CeReportServerType.ceServerTypeUserSpecified;
              newRpt.ReportLogons[j].CustomDatabaseDLLName = "crdb_olap.dll";
              break;
            case DBDrivers.XML:
              newRpt.ReportLogons[j].CustomServerType = CeReportServerType.ceServerTypeUserSpecified;
              newRpt.ReportLogons[j].CustomDatabaseDLLName = "crdb_xml.dll";
              break;
          }
        }
      }
    }


-Dell

Show 3 Share
10 |10000 characters needed characters left characters exceeded
Former Member

Thanks everyone for the additional information. Would "ReplaceConnection oracle" and "ReplaceConnection sql server" be goods ways to search for how the replaceconnection method is used?

0
Former Member

Hi would you know where I can find an example for using replaceconnection? all I have found on the SAP website is examples in JAVA. I am looking for an example in C# thanks

0

I'm not entirely sure that replaceconnection is available in .NET. You can download the developer documentation from the "Related Content" section here: https://wiki.scn.sap.com/wiki/display/BOBJ/Crystal+Reports%2C+Developer+for+Visual+Studio+Downloads

The API guide should have information on it if it is available.

-Dell

1
avatar image
Former Member Jun 29, 2017 at 05:41 PM
0

See question about code below

Show 3 Share
10 |10000 characters needed characters left characters exceeded
Former Member

Thanks Dell for the sample code and the reply. My version of the report document object does not have a ReportLogins collection or other properties in your example. Would you be able to tell me what service packs you are using installed? I am using Visual Studio 2013. I have Crystal Reports Basic for Visual Studio 2008, Crystal Reports Basic Runtime for Visual Studio 2008 (x64) runtime installed and Crystal Reports XI Release 2 installed for developing reports. From what I have seen on the SAP website, I need service pack 15 to be downloaded and installed. Thanks Ben

0

The versions that you have (2008 and XIr2) will NOT work in Visual Studio 2010 or newer. Instead, you need to go to http://www.crystalreports.com/crystal-reports-visual-studio/ in order to download Crystal for Visual Studio. You want the "Installation Package for Visual Studio IDE" for integration into VS. The other downloads are various runtime installs to be used only when you deploy your application - DO NOT install them on your development computer! There's also a link to documentation and code samples at the bottom of the screen.

-Dell

0
Former Member

Hi Dell thanks for replying.

We use crystal reports designer 2013 to develop the reports. I am using Visual studio 2013 and the .net SDK. The replace connection method has an overload when I bring it up in my test application. The Replace connection overload is available from the sample code below. I wonder how to get the old connection from the report and Why types of new connection objects the ReplaceConnection method will take.

ReportDocument rpt = newReportDocument();

rpt.Load("file path to crystal 13 report");

CrystalDecisions.ReportAppServer.ClientDoc.ISCDReportClientDocument rptClientDoc;

rptClientDoc = rpt.ReportClientDocument;

object oldconn = "to be defined from report";

object newconn = "new connection to be defined for the report";

object parameterfields = "parameter fields";

rptClientDoc.DatabaseController.ReplaceConnection(oldconn, newconn, parameterfields);

Thanks Ben
0
Don Williams
Jul 19, 2017 at 03:28 PM
0

On the download page there is a link for a parameter test app:

https://blogs.sap.com/2016/02/17/how-to-parameters-in-crystal-reports-for-visual-studio-net/

It has a ReplaceConnection button, use it to set the info and the DB connection info is retrieved via the Load() routine:

// get the DB name from the report
CrystalDecisions.CrystalReports.Engine.Database crDatabase;
CrystalDecisions.CrystalReports.Engine.Tables crTables;
crDatabase = rpt.Database;
crTables = crDatabase.Tables;
int dbx = 0;
btnSQLStatement.Text += "\nMain Report Table count: " + rpt.Database.Tables.Count.ToString();

foreach (CrystalDecisions.CrystalReports.Engine.Table crTable in crTables)
{
if (crDatabase.Tables.Count != 0)
{
CrystalDecisions.Shared.NameValuePair2 nvp2 = (NameValuePair2)rpt.Database.Tables[dbx].LogOnInfo.ConnectionInfo.Attributes.Collection[1];
btnSQLStatement.Text += "\nRPT Data Source Info: \n" + " Server Name: " + rpt.Database.Tables[dbx].LogOnInfo.ConnectionInfo.ServerName.ToString() + "\n Database Name: " + nvp2.Value.ToString() + "\n Table Name: " + rpt.Database.Tables[dbx].Name.ToString();
if (rpt.Database.Tables[dbx].LogOnInfo.ConnectionInfo.UserID != null)
btnSQLStatement.Text += "\n User ID: " + rpt.Database.Tables[dbx].LogOnInfo.ConnectionInfo.UserID.ToString() + "\r\n";
dbx++;
}
else
btnSQLStatement.Text += "No Data source or not found\r\n";
}

Now search for subreports and get it's connection properties.

It's in the private void ReplaceConnection_Click... routine.

Don

Show 1 Share
10 |10000 characters needed characters left characters exceeded
Former Member

Hi Don, could you explain the statement

[dbx].LogOnInfo.ConnectionInfo.ServerName.ToString() + "\n Database Name: " + nvp2.Value.ToString() + "\n Table Name: " + rpt.Database.Tables[dbx].Name.ToString();

to me. I have never seen an integer referenced in code like this in over the 13 years I have been coding in C#

Thanks

0
Don Williams
Jul 21, 2017 at 03:09 PM
0

Not sure what you are referring to, please explain? They are all labels or indexes as I see them...

Show 2 Share
10 |10000 characters needed characters left characters exceeded
Former Member

Hi Don,

Ok I see the rpt.Database.Tables[dbx] table indexing; my fault. However, all this code is doing is setting the text property of buttons. The sample application that I downloaded via Dell's hyperlink, but like the code above, is similar in function to the code above. I have chosen to re-posted my question to start over fresh and I have asked my question as succinctly as possible. Also this is my first time ever interacting with other people over the web in this way. Thank you

0

Not correct, rpt.Database.Tables[dbx] is a pointer to each table in the report, has nothing to do with buttons.

0