無法連接: 登入參數錯誤。
OLE DB 當時是不能使用
更新為最新的 Oracle Server 為Crystal Report 中資料庫的位置。
問題2︰
更改Crystal Report 中資料庫的位置,必須同時修改 每個Table / View / procedure / SubReport,另外同時增加Oracle Schema 才能正常導出PDF / Crystal report viewer
public static void changeCrystalReportConnectionInfo(ref ReportDocument CrReport, string schema_name)
{
// get conncetion string info
string connstring =
ConfigurationManager.ConnectionStrings[schema_name + "_Entities"].ConnectionString;
string ProviderName =
ConfigurationManager.ConnectionStrings[schema_name + "_Entities"].ProviderName;
EntityConnectionStringBuilder entityBuilder = new EntityConnectionStringBuilder(connstring);
OracleConnectionStringBuilder builder =
new OracleConnectionStringBuilder(entityBuilder.ProviderConnectionString);
string[] userTableArray = { "MEMBERDB", "MEMBERDB_OBRAS", "USER_SUBST", "USERDB", "UUU" };
// set crystal report connection info
ConnectionInfo crconnectioninfo = new CrystalDecisions.Shared.ConnectionInfo();
crconnectioninfo.ServerName = builder.DataSource;
crconnectioninfo.DatabaseName = builder.UserID;
crconnectioninfo.UserID = builder.UserID;
crconnectioninfo.Password = builder.Password;
crconnectioninfo.IntegratedSecurity = false;
foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrReport.Database.Tables)
{
int dosIndex = CrTable.Location.LastIndexOf(".");
string orgSchemaName = CrTable.Location.Split((".").ToCharArray())[0];
string newSchemaName = crconnectioninfo.UserID.ToUpper();
CrTable.LogOnInfo.ConnectionInfo = crconnectioninfo;
CrTable.ApplyLogOnInfo(CrTable.LogOnInfo);
List newddf = userTableArray.Where(x => CrTable.Location.LastIndexOf(x) >= 0).ToList();
if (newddf.Count()>0)
{
newSchemaName = "USERMANAGER";
}
if (dosIndex > 0) {
CrTable.Location = newSchemaName + "." + CrTable.Location.Substring(dosIndex < 0 ? 0 : dosIndex + 1, CrTable.Location.Length - orgSchemaName.Length - 1);
}
else
{
CrTable.Location = newSchemaName + "." + CrTable.Location;
}
}
//Set subreport connection string.
//If you have subreport inside subreport, please add more code. This code only support one level of subreport.
CrystalDecisions.CrystalReports.Engine.SubreportObject SubRptO;
CrystalDecisions.CrystalReports.Engine.ReportDocument SubRptD;
for (int index = 0; index <= CrReport.ReportDefinition.Sections.Count - 1; index++)
{
for (int intCounter = 0; intCounter <= CrReport.ReportDefinition.Sections[index].ReportObjects.Count - 1; intCounter++)
{
var _with1 = CrReport.ReportDefinition.Sections[index];
if (_with1.ReportObjects[intCounter].Kind == CrystalDecisions.Shared.ReportObjectKind.SubreportObject)
{
SubRptO = (CrystalDecisions.CrystalReports.Engine.SubreportObject)_with1.ReportObjects[intCounter];
SubRptD = SubRptO.OpenSubreport(SubRptO.SubreportName);
for (int intCounter1 = 0; intCounter1 <= SubRptD.Database.Tables.Count - 1; intCounter1++)
{
int dosIndex = SubRptD.Database.Tables[intCounter1].Location.LastIndexOf(".");
string orgSchemaName = SubRptD.Database.Tables[intCounter1].Location.Split((".").ToCharArray())[0];
SubRptD.Database.Tables[intCounter1].LogOnInfo.ConnectionInfo = crconnectioninfo;
SubRptD.Database.Tables[intCounter1].ApplyLogOnInfo(SubRptD.Database.Tables[intCounter1].LogOnInfo);
if (dosIndex > 0)
{
SubRptD.Database.Tables[intCounter1].Location = crconnectioninfo.UserID.ToUpper() + "." + SubRptD.Database.Tables[intCounter1].Location.Substring(dosIndex < 0 ? 0 : dosIndex + 1, SubRptD.Database.Tables[intCounter1].Location.Length - orgSchemaName.Length - 1);
}
else
{
SubRptD.Database.Tables[intCounter1].Location = crconnectioninfo.UserID.ToUpper() + "." + SubRptD.Database.Tables[intCounter1].Location;
}
}
}
}
}
}