I use Crystal reports for reporting my application. The problem is that i didn't know how
to set the connection infos for Crystal reports. this is the code i tried:
private void button5_Click(object sender, EventArgs e)
{
ReportDocument cryRpt = new ReportDocument();
TableLogOnInfos crtableLogoninfos = new TableLogOnInfos();
TableLogOnInfo crtableLogoninfo = new TableLogOnInfo();
ConnectionInfo crConnectionInfo = new ConnectionInfo();
Tables CrTables;
crConnectionInfo.ServerName = ".\\SQLEXPRESS";
crConnectionInfo.DatabaseName = "GestStock.mdf";
crConnectionInfo.UserID = "";
crConnectionInfo.Password = "";
CrTables = cryRpt.Database.Tables;
cryRpt.Load("C:\\Documents and Settings\\Administrateur\\Mes documents\\GestionStock\\GestionStock\\CrystalReport1.rpt");
foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables)
{
crtableLogoninfo = CrTable.LogOnInfo;
crtableLogoninfo.ConnectionInfo = crConnectionInfo;
CrTable.ApplyLogOnInfo(crtableLogoninfo);
}
crystalReportViewer1.ReportSource = cryRpt;
crystalReportViewer1.Refresh();
}
But it doesn't work i got this error message:
Chemin d'accès au fichier de rapport non valide (Invalid report file path)
PS: this the connectionstring of my sql server database:
"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\DOCUMENTS AND SETTINGS\ADMINISTRATEUR\MES DOCUMENTS\GESTIONSTOCK\GESTIONSTOCK\GestStock.mdf;Integrated Security=True;User Instance=True";
So how to set it in a correct way?