Results 1 to 4 of 4

Thread: Crystal Reporting and database path

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2007
    Posts
    228

    Crystal Reporting and database path

    Hi Guys

    I set up a report using the report wizard and access DB. After i installed the program on another pc it tries to find the DB using the path thats on my pc.
    How can i fix this so the path will be at my.application.info.directoryPath. Do i have to create the report all from code.

    Thanks

  2. #2
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: Crystal Reporting and database path

    What version of VB, and CR? You should have access to the Connection Info properties of the report and can set the database path and name there
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Aug 2007
    Posts
    228

    Re: Crystal Reporting and database path

    Im using visual studio 2005 pro, and Crystal reports that come with this, 10.2
    I created the Reports at design time so the database is already assigned to the Report.rpt. I just need to set the past diffrent from the one already set else every pc i install this software on, it will look for the database on "e:\Development" where i need the software to look for the DB on My.Application.Info.Directory

    Im not sure how to set the Path.

  4. #4
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: Crystal Reporting and database path

    There are post in this section on chaning the database location (path). You need to use a Sub that will modify the ConnectionInfo property of the report for each table in the report and each sub report (and its tables) in that main report.

    This is the code I use (this SQL Server):

    vb.net Code:
    1. Imports CrystalDecisions.Shared
    2.  
    3.     Public Sub outputToPrinter(ByVal mRepName As String, ByVal mstrW As String, Optional ByVal strPars As String = "")
    4.         Dim ConInfo As New CrystalDecisions.Shared.TableLogOnInfo
    5.         Dim paraValue As New CrystalDecisions.Shared.ParameterDiscreteValue
    6.         Dim currValue As New CrystalDecisions.Shared.ParameterValues
    7.         'Sub report object of crystal report.
    8.         Dim mySubReportObject As CrystalDecisions.CrystalReports.Engine.SubreportObject
    9.         'Sub report document of crystal report.
    10.         Dim mySubRepDoc As New CrystalDecisions.CrystalReports.Engine.ReportDocument
    11.         Dim i, x, z As Integer 'Some Counters
    12.         Dim mRep As New CrystalDecisions.CrystalReports.Engine.ReportDocument
    13.  
    14.         Try
    15.             ' Load the report
    16.             'Need to add the Report dll yet nothing works
    17.             Dim rep As New RSMReports.clsReports(mRepName)
    18.             mRep = rep.returnRep()
    19.             mRep.RecordSelectionFormula = mstrW
    20.  
    21.             ConInfo.ConnectionInfo.UserID = UserName
    22.             ConInfo.ConnectionInfo.Password = Password
    23.             ConInfo.ConnectionInfo.ServerName = mdlGeneral.serverName
    24.             ConInfo.ConnectionInfo.DatabaseName = mdlGeneral.dbName
    25.  
    26.             For i = 0 To mRep.Database.Tables.Count() - 1
    27.                 mRep.Database.Tables(i).ApplyLogOnInfo(ConInfo)
    28.             Next i
    29.  
    30.             'Check for Subreprots
    31.             For i = 0 To mRep.ReportDefinition.Sections.Count - 1
    32.                 For x = 0 To mRep.ReportDefinition.Sections(i).ReportObjects.Count - 1
    33.                     With mRep.ReportDefinition.Sections(i)
    34.                         If .ReportObjects(x).Kind = CrystalDecisions.Shared.ReportObjectKind.SubreportObject Then
    35.                             mySubReportObject = CType(.ReportObjects(x), CrystalDecisions.CrystalReports.Engine.SubreportObject)
    36.                             mySubRepDoc = mySubReportObject.OpenSubreport(mySubReportObject.SubreportName)
    37.                             For z = 0 To mySubRepDoc.Database.Tables.Count - 1
    38.                                 mySubRepDoc.Database.Tables(z).ApplyLogOnInfo(ConInfo)
    39.                             Next z
    40.                         End If
    41.                     End With
    42.                 Next x
    43.             Next i
    44.             'Parameter Fields
    45.             If strPars.Trim() <> String.Empty Then
    46.                 Dim arPars As String() = strPars.Split("~")
    47.                 Dim strVal As String()
    48.                 For xx As Integer = 0 To arPars.GetUpperBound(0)
    49.                     strVal = arPars(xx).Split("=")
    50.                     paraValue.Value = strVal(1)
    51.                     currValue = mRep.DataDefinition.ParameterFields(strVal(0)).CurrentValues
    52.                     currValue.Add(paraValue)
    53.                     mRep.DataDefinition.ParameterFields(xx).ApplyCurrentValues(currValue)
    54.                 Next
    55.             End If
    56.             mRep.PrintToPrinter(1, False, 0, 0)
    57.         Catch crExp As CrystalDecisions.CrystalReports.Engine.LoadSaveReportException
    58.             MessageBox.Show("Error printing Report " & mRepName & System.Environment.NewLine & _
    59.                 "The error number is: " & Err.Number.ToString() & System.Environment.NewLine & _
    60.                 "The error Message is: " & System.Environment.NewLine & crExp.Message.Trim(), "Print Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
    61.         Catch ex As Exception
    62.             MessageBox.Show("Error printing Report " & mRepName & System.Environment.NewLine & _
    63.                             "The error number is: " & Err.Number.ToString() & System.Environment.NewLine & _
    64.                             "The error Message is: " & System.Environment.NewLine & ex.Message.Trim(), "Print Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
    65.         Finally
    66.             mRep.Dispose()
    67.         End Try
    68.     End Sub
    Last edited by GaryMazzone; Jan 23rd, 2008 at 09:19 AM. Reason: Add Code to change db location
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width