Questa domanda alle persone che hanno esperienza con CR.Report Crystal e problemi con la connessione
Ho un problema con la connessione impostata al report Crystal. Ho ricevuto un rapporto dal mio cliente. La struttura del database è la stessa sul suo e sul mio server. Ma il nome di server e db è diverso. Sta usando "Comando" per creare report (comando Aggiungi nei campi Database-> Esperto database ...). Questo comando ha una funzione per la restituzione dei dati. Provo ad eseguire questo rapporto sul mio computer e ho un problema quando provo ad eseguire TestConnectivity(). Questo metodo restituisce false. Provo a eseguire il debug e ho scoperto che dopo aver applicato l'oggetto interno ApplyLogOnInfo() RasTable ha un vecchio ConnectionInfo.
Sto utilizzando il codice successivo per il collegamento set:
private void ApplyConnection(ReportDocument report, ConnectionInfo connectionInfo)
{
ApplyLogOnInfo(report, connectionInfo);
ApplyLogOnInfoForSubreports(report, connectionInfo);
}
private void ApplyLogOnInfo(ReportDocument reportDocument, ConnectionInfo connectionInfo)
{
foreach (Table table in reportDocument.Database.Tables)
{
table.LogOnInfo.ConnectionInfo.AllowCustomConnection = true;
TableLogOnInfo tableLogonInfo = table.LogOnInfo;
tableLogonInfo.ConnectionInfo = connectionInfo;
table.ApplyLogOnInfo(tableLogonInfo);
_log.InfoFormat("Table connection state: TableName = {0}, IsConnect = {1}", table.Name, table.TestConnectivity());
}
}
private void ApplyLogOnInfoForSubreports(ReportDocument reportDocument, ConnectionInfo connectionInfo)
{
Sections sections = reportDocument.ReportDefinition.Sections;
foreach (Section section in sections)
{
ReportObjects reportObjects = section.ReportObjects;
foreach (ReportObject reportObject in reportObjects)
{
_log.InfoFormat("Type = {0}, Name = {1}",reportObject.Name, reportObject.Kind);
if (reportObject.Kind == ReportObjectKind.SubreportObject)
{
var subreportObject = (SubreportObject)reportObject;
ReportDocument subReportDocument = subreportObject.OpenSubreport(subreportObject.SubreportName);
ApplyLogOnInfo(subReportDocument, connectionInfo);
}
}
}
}
Quindi le mie domande sono:
- Come posso impostare la connessione diritto di comandare?
- Perché non riesco a cambiare la connessione? (se il report è stato creato su un altro server).