How can I set a crystal report datasource from app.config ? I think which will help me to move application to different servers without the help of a developer. I have already tried with an attempt to connect with a dataset.
Database: 'Integrity security=True'
I wanted to take a report filtered by Order No.
For that I created a datatable 'Order details' (with inner join queries) in dataset and connected it with crystal report, and used record selection formula to filter 'OrderNo', But While it loading runtime, showing database login screen to enter Database login ID,Password, etc .
Can someone help to solve the issue or advice any other method ? As per my current method, will this take too much load time ? or can I use a 'parameterized Datatable adapter' ? if yes how ?
Sawmany disputes..
code for loading:
Dim cryRpt As New ReportDocument
Dim con As New SqlConnection
Dim cmd As New SqlCommand
Dim path As String = ""
Dim READER As SqlDataReader
Dim path As String = "C:\Users\MYPC\Documents\Visual Studio 2010\Projects\Laundry MasterLap\Laundry Master\Reports\reportOrderPrint.rpt"
cryRpt.Load(path)
cryRpt.SetParameterValue(0, OrderNo)
CrystalReportViewer1.ReportSource = cryRpt
CrystalReportViewer1.Refresh()
It is not possible to for crystal reports take credentials directly from app.config. You need to pass ConnectionInfo class for passing database credential to crystal reports
Import following name space
Imports CrystalDecisions.CrystalReports.Engine
import CrystalDecisions.Shared
in your function
Dim Logoninfos As new TableLogOnInfos
Dim Logoninfo As new TableLogOnInfo
Dim conInfo As new ConnectionInfo
Dim crTable As CrystalDecisions.CrystalReports.Engine.Table
Dim cryRpt As New ReportDocument
Dim path As String = "C:\Users\MYPC\Documents\Visual Studio 2010\Projects\Laundry MasterLap\Laundry Master\Reports\reportOrderPrint.rpt"
cryRpt.Load(path)
Put the database Name, Server name etc here
conInfo.ServerName = "SERVER NAME";
conInfo.DatabaseName = "DATABASE NAME";
conInfo.UserID = "USERNAME";
conInfo.Password = "PASSWORD";
Assign it to the every table in your datasource
for each CrTable in cryRpt.Database.Tables
crtableLogoninfo = CrTable.LogOnInfo
crtableLogoninfo.ConnectionInfo = crConnectionInfo
CrTable.ApplyLogOnInfo(crtableLogoninfo)
next
CrystalReportViewer1.ReportSource = cryRpt
CrystalReportViewer1.Refresh()