2010-12-14 6 views
0

Ich muss in der Lage sein, eine Datenquelle für Access-und xBase-Typen in einer RPT-Datei, die ich in einer .NET-Anwendung geladen habe.Wie programmiere ich Dateispeicherorte programmatisch in einer C# .NET App für Crystal XI R2 für Access- oder DBASE-Dateien?

Ich habe das versucht.

 CrystalDecisions.CrystalReports.Engine.ReportDocument reportDocument1 = new CrystalDecisions.CrystalReports.Engine.ReportDocument(); 
     reportDocument1.Load(@"C:\MyCrystal.rpt", CrystalDecisions.Shared.OpenReportMethod.OpenReportByTempCopy); 

      string Constr = "MyConnectionString"; 
      // initialize an object to pull out the needed pieces for the login information. 
      SqlConnectionStringBuilder sb = new SqlConnectionStringBuilder(ConStr); 
      // Turn off integrated Security 
      foreach (IConnectionInfo i in reportDocument1.DataSourceConnections) 
      { 
       i.IntegratedSecurity = false; 
      } 

      // Set the LogonInfo for each Data Source 
      foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in reportDocument1.Database.Tables) 
      { 
       TableLogOnInfo logOnInfo = CrTable.LogOnInfo; 
       String dbtype = logOnInfo.ConnectionInfo.Attributes.Collection.LookupNameValuePair("QE_DatabaseType").Value.ToString().Trim(); 
       if (dbtype.Equals("xBase")) 
       { 
        NameValuePairs2 lp = logOnInfo.ConnectionInfo.LogonProperties; 
        foreach (NameValuePair2 nvp in lp) 
        { 
         if (nvp.Name.ToString().Trim().Equals("Data File")) 
          nvp.Value = @"C:\MyDbaseFile.dbf"; 
        } 
        CrTable.ApplyLogOnInfo(logOnInfo); 
       } 
       else if (dbtype.Equals("OLE DB (ADO)")) 
       { 
        bool sql = true; 
        NameValuePairs2 lp = logOnInfo.ConnectionInfo.LogonProperties; 
        NameValuePair2 prov = lp.LookupNameValuePair("Provider"); 
        if (!prov.Value.ToString().ToUpper().Equals("SQLOLEDB")) 
        { 
         sql = false; 
         NameValuePair2 ds = lp.LookupNameValuePair("Data Source"); 
         ds.Value = @"C:\MyAccess.mdb"; 
        } 
        if (sql) 
        { 
         // Set the connection information for the table in the report. 
         logOnInfo.ConnectionInfo.UserID = sb.UserID; 
         logOnInfo.ConnectionInfo.Password = sb.Password; 
         logOnInfo.ConnectionInfo.ServerName = sb.DataSource; 
         logOnInfo.ConnectionInfo.DatabaseName = sb.InitialCatalog; 
        } 
        CrTable.ApplyLogOnInfo(logOnInfo); 
       } 
      } 

     reportDocument1.VerifyDatabase(); 
    reportDocument1.ExportToDisk(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, @"C:\MyTest.pdf"); 

Ich bekomme eine LogOnException auf dem VerifyDatabase() (oder, wenn es dort nicht die ExportToDisk ist) Ich habe vor, die Werte abgeladen und nach, und ich sehe die Änderung ... aber ich muss etwas tun falsch. Bitte helfen Sie!

Antwort

0

Haben Sie einen Code von einem SAP-Support-Mitarbeiter dafür.