Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
Hi,
 
I have created my application in Vb.net and have used crystal report. Now the crystal report is accessing a MS-Access database to generate report. How can I provide it a dynamic path such as application's installation path in database expert ? While developing the application it connects with the database which is located in a drive of my system, but if I want to install it in client system how I will do it? How to implement the same in case of multi-user system ?
Posted 23-Apr-13 23:36pm
Comments
Ezra Neil at 13-May-13 4:35am
   
Switch to MySQL to achieve what you want easier. If you have to use MS-Access, you still can do it but you may encounter problems (the MS-Access file will be in shared folders).
mahrouch at 26-Jul-13 17:56pm
   
Same problem for me,
@Ezra Neil, how to do it with MS-Access? thanks
@Praveen21212, what did you do for your problem?
Praveen21212 at 27-Jul-13 3:28am
   
Please have a look at the solution provided below. If you have any questions please revert. Thank you.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

I found a solution and it's very simple to do. Just add connection info and apply it. Now every time when reports loads it will apply the connection info provided.
 
Private Sub frmreportviewer_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim CrTables As Tables
        Dim crtableLogoninfo As New TableLogOnInfo
        Dim crConnectionInfo As New ConnectionInfo
        Try
			'reportdoc object
            Dim cryRpt As New ReportDocument
			
            'load report
            cryRpt.Load(My.Application.Info.DirectoryPath.ToString() & "\Report1.rpt")
            
			'parameters definition(if any)
            
			'provide connection info. This is important and you can change it as per your db location
			With crConnectionInfo
                .ServerName = My.Application.Info.DirectoryPath.ToString() & "\abc.mdb"
                '.DatabaseName = ""
                '.UserID = ""
                .Password = "password"
            End With
 
            CrTables = cryRpt.Database.Tables
            For Each CrTable In CrTables
                crtableLogoninfo = CrTable.LogOnInfo
                crtableLogoninfo.ConnectionInfo = crConnectionInfo
                CrTable.ApplyLogOnInfo(crtableLogoninfo)
            Next
 
            CrystalReportViewer1.ReportSource = cryRpt
            CrystalReportViewer1.Refresh()
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
  Permalink  
Comments
evry1falls at 13-Apr-14 15:20pm
   
For Each CrTable In CrTables
Line above generate error, it would be more suitable if changed to
For Each CrTable As Table In CrTables
keval123 at 6-Jul-14 2:18am
   
You know what ? I have been trying to solve this issues since a month, Finally you did it for me
Thank a lot dud
keval123 at 6-Jul-14 12:29pm
   
HI
I need help here
Can you tell me what should I do if I want to pass parameters in the report
Something like SQL command "SELECT * FROM products WHERE product_size=500"
Help me here pls
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

If you are using Ms-Access then simply follow the code block mentioned below and connect your access database normally to the crystal report.
 
========================X========================
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
 
Public Class Form4
 
Private Sub Form4_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
Dim S As New Bills
With S
.FileName = "cryReport.RPT"
.SetDatabaseLogon("Admin", "PASSWORD")
End With
 
CrystalReportViewer1.ReportSource = S
CrystalReportViewer1.Refresh()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
 
End Class
========================X========================
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 245
1 Kamal Rocks 184
2 Sergey Alexandrovich Kryukov 175
3 BillWoodruff 173
4 PIEBALDconsult 160
0 OriginalGriff 5,655
1 DamithSL 4,506
2 Maciej Los 3,997
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,180


Advertise | Privacy | Mobile
Web04 | 2.8.141216.1 | Last Updated 20 Nov 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100