Bonjour,

Je développe une application en WPF. Dans visual studio 2010, je crée mon fichier crystal (.rpt). Je le configure à ma base de donnée en OLE DB (ADO), je remplis mon fichier tout va bien. J’exécute mon application sur mon PC ça marche très bien.

Le problème est lorsque je mets cette application sur un autre PC, donc une nouvelle BDD, ben ça ne marche pas, le viewer Crystal report me demande l'ID et MDP de connexion à la BDD, alors qu'il ne devrait pas car dans mon code en C# avant de lancer le viewer je configure le crystal report avec les nouvelles données BDD.

Quelqu'un peut m'aider? Faut-il que je crée autrement mon fichier "rpt"? peut-on passer en paramètre du report (en c#) un fichier UDL?

A mon avis ce n'est pas un problème C# mais Crystal Report

Voici mon code pour la configuration dynamique :

// create report document object
var rdCrystalReport = new ReportDocument();

// combines two strings into a path.
string path = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"..\..\" + reportFilePath);
rdCrystalReport.Load(path);

SqlConnectionStringBuilder scnxstrbldConnexion = new SqlConnectionStringBuilder(System.Configuration.ConfigurationManager.ConnectionStrings["DatabaseConnString"].ConnectionString);

ConnectionInfo connectionInfo = new ConnectionInfo();
connectionInfo.ServerName = scnxstrbldConnexion.DataSource;
connectionInfo.DatabaseName = scnxstrbldConnexion.InitialCatalog;
connectionInfo.UserID = scnxstrbldConnexion.UserID;
connectionInfo.Password = scnxstrbldConnexion.Password;
connectionInfo.IntegratedSecurity = false;

foreach (ReportDocument subReport in rdCrystalReport.Subreports) {
foreach (Table crTable in subReport.Database.Tables) {
TableLogOnInfo loi = crTable.LogOnInfo;
loi.ConnectionInfo.ServerName = connectionInfo.ServerName;
loi.ConnectionInfo.DatabaseName = connectionInfo.DatabaseName;
loi.ConnectionInfo.UserID = connectionInfo.UserID;
loi.ConnectionInfo.Password = connectionInfo.Password;
crTable.ApplyLogOnInfo(loi);
}
}

//Loop through each table in the report and apply the new login information (in our case, a DSN)
foreach (Table crTable in rdCrystalReport.Database.Tables)
{
TableLogOnInfo loi = crTable.LogOnInfo;
loi.ConnectionInfo.ServerName = connectionInfo.ServerName;
loi.ConnectionInfo.DatabaseName = connectionInfo.DatabaseName;
loi.ConnectionInfo.UserID = connectionInfo.UserID;
loi.ConnectionInfo.Password = connectionInfo.Password;

crTable.ApplyLogOnInfo(loi);
}