Click here to Skip to main content
15,881,635 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Comments
Ezra Neil 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 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 27-Jul-13 3:28am    
Please have a look at the solution provided below. If you have any questions please revert. Thank you.

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.

VB
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
 
Share this answer
 
Comments
evry1falls 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
Keval Savani 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
Keval Savani 6-Jul-14 12:29pm    
HII 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
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========================
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900