Change datasource of Crystal Report via code

Hi all!
I'm developing partner solution for SAP B1 8.8 in C# and prepared some nice crystal reports. But they are bound to my default database for now. I want to include them to my installation file and change saved datasource location (Server, Company Name, User name, User password) in my installation script as soon as I get this values, entered by user. But I don't know the way how to change datasource in rpt file. I've tried the following:
using CrystalDecisions.CrystalReports.Engine;
ReportDocument rDoc = new ReportDocument();
rDoc.Load(@"C:\Temp\Report2.rpt");
rDoc.DataSourceConnections[0].SetConnection("Server", "SBOTest", "manager", "manager");
rDoc.SaveAs(@"C:\Temp\Report3.rpt");
rDoc.Close();
but it save no changes to rpt file.
I think, this thread belongs mostly to Development/SDK thread, because here most of the people make programs and potentially met this problem in the past.

public void SetCrystalLogin(string sUser, string sPassword, string sServer, string sCompanyDB, CrystalDecisions.CrystalReports.Engine.ReportDocument oRpt)
            CrystalDecisions.Shared.ConnectionInfo oConnectInfo = new CrystalDecisions.Shared.ConnectionInfo();
            oConnectInfo.DatabaseName = sCompanyDB;
            oConnectInfo.ServerName = sServer;
            oConnectInfo.UserID = sUser;
            oConnectInfo.Password = sPassword;
            // Set the logon credentials for all tables
            SetCrystalTablesLogin(oConnectInfo, oRpt.Database.Tables);
            // Check for subreports
            foreach (CrystalDecisions.CrystalReports.Engine.Section oSection in oRpt.ReportDefinition.Sections)
                foreach (CrystalDecisions.CrystalReports.Engine.ReportObject oRptObj in oSection.ReportObjects)
                    if (oRptObj.Kind == CrystalDecisions.Shared.ReportObjectKind.SubreportObject)
                        // This is a subreport so set the logon credentials for this report's tables
                        CrystalDecisions.CrystalReports.Engine.SubreportObject oSubRptObj = oRptObj as CrystalDecisions.CrystalReports.Engine.SubreportObject;
                        // Open the subreport
                        CrystalDecisions.CrystalReports.Engine.ReportDocument oSubRpt = oSubRptObj.OpenSubreport(oSubRptObj.SubreportName);
                        SetCrystalTablesLogin(oConnectInfo, oSubRpt.Database.Tables);
            oRpt.Refresh();
            oRpt.SetDatabaseLogon(sUser, sPassword, sServer, sCompanyDB, false);
            oRpt.VerifyDatabase();
            oRpt.Refresh();
        private void SetCrystalTablesLogin(CrystalDecisions.Shared.ConnectionInfo oConnectInfo, Tables oTables)
            foreach (CrystalDecisions.CrystalReports.Engine.Table oTable in oTables)
                CrystalDecisions.Shared.TableLogOnInfo oLogonInfo = oTable.LogOnInfo;
                oLogonInfo.ConnectionInfo = oConnectInfo;
                oTable.ApplyLogOnInfo(oLogonInfo);
Edited by: Konstantin Rakhuba on May 6, 2010 11:44 AM
Edited by: Konstantin Rakhuba on May 6, 2010 11:45 AM

Similar Messages

  • Can we launch Crystal Report via Browser?

    Hi, Experts
    I have created a Balance Sheet report (T-Style) with the help of BOBJ-Crystal Reorts.
    But I wanna to consume this report via Browser, neither email with PDF/Excel attached, nor Crystal Report 2008 designer.
    Is there any solution/tool to make this happen?
    How can I implement it?
    Thanks a lot.
    Peter Zhou

    You are able to view Crystal Reports via a browser in a few ways.
    1. Report is published to Enterprise and you use Infoview to browse to the report and view.
    2. Report is published to Enterprise and you use a custom application written in .NET/JAVA to view the report, loading it from your enterprise server.
    3. Report is stored on disk and you use a custom application written in .NET/JAVA to view the report.
    For viewing in a custom application please visit [diamond.businessobjects.com|http://diamond.businessobjects.com/]
    The documentation for the SDK's can be found in the Developer Library, and sample code can be found under the Sample Code.

  • How to transport Parameter changes in a crystal report

    Hi All,
    Very Good morning!!!
    I have designed a crystal report with static parameters. Earlier i used to have a dropdown kind of input selection for my parameters.
    Now i got a new requirement for a direct input in the field....tht means no dropdown ...single date field is to be entered directly.
    Accordingly i have removed the dropdown and changed to a single direct date field. I saved these changes to a request and transported to quality. Not sure whether the parameter changes are collected into a request.
    Whereas i couldn't found any changes of my parameters in quality. They are as same dropdown manner in the quality whereas i need them to be a direct field date entry which did not affected the quality server after transporting the changes.
    Could some one please let me know how to reflect these changes in quality server regarding parameter changes in a crystal report for BW.
    Thanks in Advance.
    Jitendra

    Please re-post if this is still an issue or purchase a case and have a dedicated support
    engineer work with your directly

  • Pls Help: View Crystal Report Via Oracle Form Builder

    Hi!!
    I want to know how to view the .rpt report (report made from Crystal Report) via Oracle Form Builder. I've to do it in my project. If you know, please tell me.
    Thanks in advance,

    I don't know how does crystal reports work, and I would guess you should ask the crystal guys to help you with this. find out if they have a command line interface that you can invoke from the host command in forms.
    We can help you do it with Oracle Reports though :-)
    http://otn.oracle.com/products/reports

  • Database structure changed. Mapping Crystal reports to new datasource

    There are several crystal reports that need to be remapped to a new database we have in place. The data structure has quite changed. I started using the 'Set datasource Location' option to map the new database fields to existing fields in the report. The problem shows up when trying to map fields from multiple tables to existing fields in the report from a single table. To elaborate, the old database structure has only one table used for a report and the new database structure has these same fileds coming from two different tables. The 'Set datasource Location'  option is leting me map the existing table used in the report to only one report. Is this how this functionality works or am I missing something. Please advise the best way to do this mapping.
    VJ

    hi VJ,
    when you're dealing with reports where the data source can change along with the number of tables or the table names or the field names etc. then this is a method that you can design with to avoid issues associated with datasource changes.
    you can also change existing reports to use this formula only method but of course there's a bit of work involved in changing reports vs. designing them like this from the ground up.
    -jamie

  • Open a draft report via Code

    How could I open an saved Draft report via API/UI.
    I have draft an report via API/UI and now I would show this report on Desktop/SAP
    I would open it via code
    z.B. application.forms.items("")
    because I get the Docnum of my before safed draft but It wouldn´t shown at the SAP now so I have to open it via code

    Sorry for my first Miss Understandable explanation.
    Ok let me explain the other times.
    I have a parked document, I want this now to open it via code (programming).
    I have this code today:
    programspeach: vb.net
    we assume we have a sales order and press now via code the menu option "Save as a parked document"
    ' to change the sales order in a parked document
    appl.ActivateMenuItem(("5907"))
    ' Information: MY_FormUID = the sales order before
    ' Change DocNum in DocEntry
    oRSTRDocData.DoQuery(("SELECT max(DocEntry) FROM ODRF WHERE DocNum=" & Value))
    appl.Forms.Item(MY_FormUID).Items.Item("txtDraft").Specific.Value = oRSTRDocData.Fields.Item(0).Value
    ' take the DocEntry
    Value = oRSTRDocData.Fields.Item(0).Value
    'open parked Document via DocEntry and let it show
    appl.Forms.Item(MY_FormUID).Items.Item("lnkDraft").Click(SAPbouiCOM.BoCellClickType.ct_Linked)
    ' Close the Sales Order before
    appl.Forms.Item(OLD_FormUID).Close()
    After this there is no Document opened, also not the parked Document
    So yet I have an parked Document but when I open the SBO again there is no Document Opened? When I do this prozedere via SBO there will be at least the parked Document opened.
    What do I wrong?

  • Unable to fill datatable to use as datasource for Crystal Report

    Hello again kind folks of the Crystal Reports forums. I beseech you for a little assistance yet again. I am writing a program that does some very simple stuff, yet is giving me very complicated problems. I used the code I wrote from a working program and everything is fine, except the fact I can't get data on my report.  I have created a dataset    to get the data from my SQL Server database. The connection string I have works, and the query I use works. In my other program I when I look at the dataset.xsd I see a filled datatable and that was how I got my fields for the report. In this one, I don't know how to prefill the datatable so that I can use that as a datasource in my report. I would be glad to get you code if anyone would like it. If someone could explain to me how to fill the datatable so I can use it as the crystal datasource, I would be so appreciative.
    Thanks again for all your help.
    Jami Benson

    Thanks for posting a reply Amit. I am confused about a couple things. The XML file. Is that something that I have to create myself? In my last program I got around using XML files somehow and for the life of me I can't remember how I did it. Is there another way you know of to fill besides this? Also I dont' have access on my computer. The boss never say a need since no one uses it. Is there a way to use my code, which I'm gonna include, and do it??
    Many thanks again Amit!
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.Data.SqlClient;
    using CrystalDecisions.CrystalReports.Engine;
    using CrystalDecisions.Shared;
    namespace SeriesPublishedToWeb
       public partial class Form1 : Form
          #region Configurable Settings
          private string connectionString = "Data Source =SQLSERVER; User ID=NightOps; Password=BTSB; Initial Catalog =BTSB";
          #endregion
          public Form1()
             InitializeComponent();
          private void runReport_Click(object sender, EventArgs e)
             CrystalReport1 crReportDocument = new CrystalReport1();
             BTSBDataSet dataSet = new BTSBDataSet();
             using (SqlConnection conn = new SqlConnection(connectionString))
                try
                   conn.Open();
                catch (SqlException Ex)
                   if (conn != null)
                      conn.Dispose();
                   string ErrorMessage = "A error has occured while trying to connect to the server.";
                   ErrorMessage += Environment.NewLine;
                   ErrorMessage += Environment.NewLine;
                   ErrorMessage += Ex.Message;
                   MessageBox.Show(this, ErrorMessage, "Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                   return;
                string SQLSTATEMENT = "select t.titleno, title, season_code, series, field " +
                                      "from btsblog b JOIN TMASTER t on b.selectionid = t.titleno JOIN TMASTEREXT e  on e.titleno = t.titleno " +
                                      "where timestamp >= '3/1/09' " +
                                      "and timestamp <= '4/3/09' " +
                                      "and field = 'Publishtoweb' " +
                                      "and datawas = 'N' " +
                                      "and datais = 'Y' " +
                                      "and season_code = 'B'  " +
                                      "and series <> ' '";                                                                               
    using (SqlDataAdapter SQLDataAdapter = new SqlDataAdapter(SQLSTATEMENT, conn))
                   // this is the dataset that will fill the data adapter
                   SQLDataAdapter.Fill(dataSet.Tables["BTSBDataTable"]);
                //this should launch the crystal on form 2
                crReportDocument.SetDataSource(dataSet);
                //show the crystal
                frmCrystal reportViewer = new frmCrystal(crReportDocument);
                reportViewer.Refresh();
                reportViewer.ShowDialog();

  • Error while trying to save a crystal report via the Add-ins

    Hi All,
    I'm getting an error while trying to save the crystal report after I have opened it from the SAP.
    When I'm trying to save the report via the Add-ins I'm getting the next error :
    Unknown error accured failed to get the internal key of the current user.
    Thanks for your help,
    Eyal

    Hi Eyal,
    Even though you posted your 1st message couple of month ago, I would still say welcome you to post on the forum.
    What is your B1 version and PL?
    Thanks,
    Gordon

  • Error while trying to load Crystal report via Windows service

    Hi,
    I am trying to generate PDF file using crystal reports. I have developed a console application which works absolutely fine, however when I converted the code to work as windows service (wcf hosted in Windows service), this below error I see from stack trace:
    Load report failed.
    at CrystalDecisions.ReportAppServer.ReportClientDocumentWrapper.EnsureDocumentIsOpened()
    at CrystalDecisions.CrystalReports.Engine.ReportDocument.Load(String filename, OpenReportMethod openMethod, Int16 parentJob)
    at CrystalDecisions.CrystalReports.Engine.ReportDocument.Load(String filename)
    at AtDataWindowsService.GetData.generatePDF(DataTable dt)
    The code used is:
    CrystalDecisions.Shared.ExportFormatType exportFormat;
    ReportDocument reportObj = new ReportDocument();
    exportFormat = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat;
    //Load the Crystal Report
    reportObj.Load("CrystalReport.rpt");
    reportObj.SetDataSource(dt);
    What might be going wrong here?

    Hello,
    Thank you for your post.
    Based on your description, I am afraid that the issue is out of support of VS General Question forum which mainly discusses
    WPF & SL designer, Visual Studio Guidance Automation Toolkit, Developer Documentation and Help System
    and Visual Studio Editor.
    I suggest that you can consult your issue directly on SAP Crystal Reports:
    http://scn.sap.com/community/crystal-reports/content?filterID=content~objecttype~objecttype[thread]
      for better solution and support.
    Best regards,
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Deplay Crystal Report via web

    Hi.
    Is there any way to deploy report in intranet.
    I have file Report.rpt and i want users to have access to it via www.
    Is there any tutorial how to do it?
    Best regards
    Lukasz Bloch

    Hi,
    There are several ways to distribute or publish the report :
    If you have BO Enterprise or Crystal Reports Server then you can publish this report and create a OpenDocument URL. This can be given to your users to view the report in Browser.
    Or
    If you want to give your report to users for just to understand the results, then try to download CR2008 offline viewer. This will help you to view .rpt files.
    Or
    If you are developing your own Web application using .NET or JAVA you can very well embed CR reports and it can be viewed through browser.
    Or
    If you have BO Enterprise, you can publish this report to your repository and all your BO users can access this report through infoview and view the report.
    You need to choose the option to view the report.
    Thanks,
    Sastry

  • Deploy Crystal Report via ClickOnce without .msi

    Hi,
    I would like to know whether it's possible to deploy Crystal Report without requiring admin rights from the installer.
    My program uses many 3rd party components. Most of them very heavyweight with licensing, COM objects etc but Crystal Report is the only one that needs a .msi install. Is it possible to include Crystal Report's dll with the application? I tried it but Crystal Report failed to load at the form saying there's something wrong with the installation (I didn't "install").

    Only way to distribute the CR runtime is via the MSM or MSI files. For links to the msm and msi files see [this|https://wiki.sdn.sap.com/wiki/pages/viewpage.action?pageId=56787567] wiki.
    Ludek

  • Crystal Report via SAP BO

    Can somebody help me?
    I am using VB6 and CR 8.5.
    How user query that we have made can be displayed in Crystal Report, how connection within it?
    an somebody gives me a sample code
    Thankss...

    Hi
    You have to access the data first with a SAP Recordset object.  Then pass the results to either an ADO recordset (through use of a loop, row by row) an or either an xml, access database or an intermediary.  You cannot pass the SAPs Recordset object direclty to CR since it doesn't not recognize it.
    You could also query directly to the tables using ADO, but i can't recall if this would be a violation of SAP data integrity requirements. (i think not since it's only a SELECT query involved)
    Hope that helps

  • Crystal Reports 2013 - Code 39 Barcode

    I was hoping someone might be able to help me getting the Code 39 function working to convert data to a barcode in Crystal Reports 2013.
    Seems to be the work around from a UFL 'u25azalea.dll' error I was receiving.
    I’m following the directions found here: http://www.azalea.com/crystal-reports-custom-functions/code-39/
    I created a new function named “Barcode” with the func_Code-39_Full code:
    Function (StringVar input)
    Local StringVar temp;
    Local StringVar chunk;
    Local NumberVar i;
    For i := 1 To Length(input) Do
    chunk := input[i];
    Select Asc (chunk)
    Case 0:
    temp := temp + "%U"
    Case 1 To 26:
    temp := temp + "$" + Chr(Asc(chunk) + 64)
    Case 27 To 31:
    temp := temp + "%" + Chr(Asc(chunk) + 38)
    Case 32:
    temp := temp + "_"
    Case 33 To 44:
    temp := temp + "/" + Chr(Asc(chunk) + 32)
    Case 45 To 46:
    temp := temp + chunk
    Case 47:
    temp := temp + "/O"
    Case 48 To 57:
    temp := temp + chunk
    Case 58:
    temp := temp + "/Z"
    Case 59 To 63:
    temp := temp + "%" + Chr(Asc(chunk) + 11)
    Case 64:
    temp := temp + "%V"
    Case 65 To 90:
    temp := temp + chunk
    Case 91 To 95:
    temp := temp + "%" + Chr(Asc(chunk) - 16)
    Case 96:
    temp := temp + "%W"
    Case 97 To 122:
    temp := temp + "+" + Chr(Asc(chunk) - 32)
    Case 123 To 126:
    temp := temp + "%" + Chr(Asc(chunk) - 43)
    Case 127:
    temp := temp + "%T";
    "*" + temp + "*"
    Then I created a new Formula named “TripNumBarcode” and dragged the Functions\CustomFunctions\Barcode (input) function into the Formula Editor window which looked like:
    Barcode ()
    I then dragged another Formula I use to calculate the trip number into this function:
    Barcode ({@TripNumber})
    But I’m getting an error of
    A string is required here.
    Any advice?

    See this KBA:
    1546515 - Error: UFL 'u25azalea.dll' that implements this function is missing
    The KBA contains a solution of sorts. The ADAPT the KAB refers to is still set for SP 9 which should be out end of March +.
    - Ludek
    Senior Support Engineer AGS Product Support, Global Support Center Canada
    Follow us on Twitter

  • Excel Datasource for Crystal Reports - BO Enterprise on Linux

    Hi,
    i've developed a report, which uses data from sap query and from an excel file (.xls). I copied the excel file to the BO-server (the user bo has rights on this path) and publish the report. But when i start the report, comes the error "could not read database information".
    Our BOE is XI 3.1 SP 3 and we use Crystal Reports 2008. BOE runs on a SLES. Is it possible to uses Excel-Datasources in this case? If it is possible, what have i to do?
    thanks & regards
    Daniel

    Hi Daniel,
    It is not supported in Linux. You can check the Supported Platforms documents for this platform. It is only available for Windows platform.
    Regards,
    Julian

  • How to use JavaBeans as Datasource for Crystal Report 10?

    I have tried to use Crystal Report 10 with Java Beans as Data Source.
    I read
    http://support.businessobjects.com/communityCS/TechnicalPapers/cr10_java_bean_datasource.pdf
    and followed all steps to use JavaBeans as a DataSource.
    I have setup all registry entry requiered for it but still getting blank dialog box for Java Beans Connectivity classes?
    If anyone have tried to use, then give suggestions.

    I have tried to use Crystal Report 10 with Java Beans as Data Source.
    I read
    http://support.businessobjects.com/communityCS/TechnicalPapers/cr10_java_bean_datasource.pdf
    and followed all steps to use JavaBeans as a DataSource.
    I have setup all registry entry requiered for it but still getting blank dialog box for Java Beans Connectivity classes?
    If anyone have tried to use, then give suggestions.

Maybe you are looking for

  • Digital signatures e-invoices

    Hello, is it possible to sign FI documents using the SAP standard methods (using SAP GUI for Windows)??? I have found many pdf documents on service.sap.com but I have still difficulty in answering the question. Regards T

  • HardDrive/Startup Disk Disapeared

    5 year old Mac Mini with little use, whilst installing new HP printer software got spinning wheel- restarted and got blinking folder & question mark Went through all recommended restart procedures no joy, did a restart from system disk ,- disk utilit

  • 5800 XM Call log problem, please help!

    Recently  I got a problem in my Nokia 5800 XpressMusic, my recent call are not shown in my call log, Whenever I dial, received or get a missed call....it show's no dialed, received or missed calls... Ex.I got 9 missed, when I opened it, it shows noth

  • Bind a list element to a java ArrayList

    Hello, I have: static ArrayList<String> myListwhich I declared static in class A. I try to bind the items in a JavaFX ListBox to A.myList, so that whenever the content of myList changes, the items in the JavaFX ListBox change too. How can this be don

  • Epson R340 will not print higher quality photo - Jobs Stopped!

    I have seen posts on this problem before but I've tried the recommendations and haven't had any luck. From IPhoto 5 (version 5.0.4) I can print regular resolution photos but if I switch to the higher resolution photos the printer stops printing. If I