Skip to Content
author's profile photo Former Member
Former Member

Setting report from ODBC to OLE DB

This is a follow-up to a question I posted on this thread - http://scn.sap.com/thread/3174326

We have a client that favours creating their Datasource Location connections within a Crystal Report with ODBC. We in turn prefer to use OLE DB and specifically SQL Server Native Client 10.0. To remedy this we are manually modifying the reports and updating the Datasource Location.

I am wondering if there is a way within the ReportDocument to programmatically change the report to use the SQL Server Native Client 10.0 OLE DB connection? If not within the ReportDocument is there another preferred method?

I have included my code below:

using CrystalDecisions.CrystalReports.Engine;

using CrystalDecisions.Shared;

using (ReportDocument reportDocument = new ReportDocument())
{
reportDocument.Load(filePath);

//Set up the connection
TableLogOnInfo dbLogon = new TableLogOnInfo();
dbLogon.ConnectionInfo.ServerName = Constants.ReportServerName;
dbLogon.ConnectionInfo.DatabaseName = Constants.ReportDatabaseName;
dbLogon.ConnectionInfo.UserID = Constants.ReportUserId;
dbLogon.ConnectionInfo.Password = Constants.ReportPassword;

//Apply logon Info to all database objects
reportDocument.Database.Tables[0].ApplyLogOnInfo(dbLogon);

//Assign Parameters
reportDocument.SetParameterValue("Date", fiscalDateId);
reportDocument.SetParameterValue("Display", pageDisplay);
reportDocument.SetParameterValue("Language", language);

//Create the report name
exportfilename = FileUtils.MapPath(string.Format("{0}\\Report_{1:yyyyMMdd}_{1:hhmmss}.csv", Constants.ExportedReportsPath, DateTime.Now));

//Generate the report and save it
reportDocument.ExportToDisk(ExportFormatType.CharacterSeparatedValues, exportfilename);
}

Thanks,

Ken

Add a comment
10|10000 characters needed characters exceeded

Related questions

2 Answers

  • Best Answer
    Posted on May 30, 2012 at 03:14 PM

    I'd use InProc RAS SDK. Then see the blog When to use the 'Replace Connection' method using the Crystal Reports or InProc RAS SDK for .NET.

    A KB worth looking at as it has an attached utility that will write out the connection code for you:

    1553921 - Is there a utility that would help in writing database logon code?

    - Ludek

    Follow us on Twitter

    Got Enhancement ideas? Try the SAP Idea Place

    Share Your Knowledge in SCN Topic Spaces

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 05, 2012 at 02:37 PM

    Hi Ludek,

    I took your advice and I used the utility to create my connection string. After the C# code was generated I then added in my connection info including username, password, server and db names. I then changed the table info to reflect the tables I am using and set the table command text to the same as the query within my report. However, I keep getting a "Log on failed" error. This occurs when I try to run VerfiyDatabase(). If I skip over this method and run to setting the connection on my report using the new connection I get the error there instead.

    So, I was wondering the following:

    1. Do you know the cause of this error? All of my connection info is correct. I can run the report manually using the same connection info. Is this a permissions issue?

    2. I noticed in the example code in the link to http://scn.sap.com/message/13295424 does not do anything with tables. I tried using this code within VS2010 and it seems like some of the classes are deprecated. Is the utility the better option than this code?

    3. Does SAP offer a service to developers where I can work with an SAP developer (over the phone or by RDP) to solve this issue if I cannot resolve it myself? Is so can you send me a link as to the cost of this service?

    Thanks again for all your help.

    Ken

    Add a comment
    10|10000 characters needed characters exceeded

    • Hello Ken:

      Trying the suggestions in When to use the 'Replace Connection' method using the Crystal Reports or InProc RAS SDK for .NET.

      may be worth while.

      To answer your questions;

      1. Do you know the cause of this error? All of my connection info is correct. I can run the report manually using the same connection info. Is this a permissions issue?

      - Could be a permissions issue -more likely with web than win apps

      2. I noticed in the example code in the link to http://scn.sap.com/message/13295424 does not do anything with tables. I tried using this code within VS2010 and it seems like some of the classes are deprecated. Is the utility the better option than this code?

      - No clases that I am aware of have been deprecated in the .NET SDK (the link links to this message)

      3. Does SAP offer a service to developers where I can work with an SAP developer (over the phone or by RDP) to solve this issue if I cannot resolve it myself? Is so can you send me a link as to the cost of this service?

      - There is a phone incident that you can create here. The costs, etc., are on that page.

      - Ludek

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.