开发者

When moving from local machine to server, Crystal requires further information to log on to database

I know this has been posted before by other users and I have tried looking at all the answers already answered and tried everything but nothing seems to be working. So here i am posting the quest开发者_开发知识库ion again with my code....Please help me out...This works fine on the local machine and the crystal report is generated but when I put it on the server it asks for further information for the database like server name, UserName, Password...Tried everything but no use....Please help...

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using CrystalDecisions.CrystalReports.Engine;
    using CrystalDecisions.Shared;
    using System.Data;
    using System.Data.SqlClient;
    using System.Configuration;
    using System.IO;

    public partial class ImageCrystal : System.Web.UI.Page
   {
      protected void Page_Load(object sender, EventArgs e)
    {


     //var connectionInfo = new ConnectionInfo();
     //    connectionInfo.ServerName = "157.182.x.xxx";
     //    connectionInfo.DatabaseName = "xxxx";
     //    connectionInfo.Password = "xxxx";
     //    connectionInfo.UserID = "xxxx";
     //    connectionInfo.Type = ConnectionInfoType.SQL;
     //    connectionInfo.IntegratedSecurity = false;

    //    for (int i = 0; i < CrystalReportViewer1.LogOnInfo.Count; i++)
    //{
    //    CrystalReportViewer1.LogOnInfo[i].ConnectionInfo = connectionInfo;
    //}

    // trying to load an image
    ReportDocument rptTest1 = new ReportDocument();
    rptTest1.Load(Server.MapPath("~/Image.rpt"));
    rptTest1.Database.Tables[0].SetDataSource(rptTest.ImageTable(Server.MapPath("~/Brochures/Test3.jpg")));

    ParameterFieldDefinitions crParameterFieldDefinitions;

    ParameterFieldDefinition crParameterFieldDefinition;
    ParameterFieldDefinition crParameterFieldDefinition1;
    ParameterValues crParameterValues = new ParameterValues();
    ParameterValues crParameterValues1 = new ParameterValues();
    ParameterDiscreteValue crParameterDiscreteValue = new ParameterDiscreteValue();
    ParameterDiscreteValue crParameterDiscreteValue1 = new ParameterDiscreteValue();

    crParameterDiscreteValue.Value = TextBox1.Text;
    crParameterFieldDefinitions = rptTest1.DataDefinition.ParameterFields;
    crParameterFieldDefinition = crParameterFieldDefinitions["CountyofArea"];
    crParameterValues = crParameterFieldDefinition.CurrentValues;

    crParameterValues.Clear();
    crParameterValues.Add(crParameterDiscreteValue);
    crParameterFieldDefinition.ApplyCurrentValues(crParameterValues);

    crParameterDiscreteValue1.Value = TextBox2.Text;
    crParameterFieldDefinitions = rptTest1.DataDefinition.ParameterFields;
    crParameterFieldDefinition1 = crParameterFieldDefinitions["Area"];
    crParameterValues1 = crParameterFieldDefinition1.CurrentValues;

    crParameterValues1.Clear();
    crParameterValues1.Add(crParameterDiscreteValue1);
    crParameterFieldDefinition1.ApplyCurrentValues(crParameterValues1);
    CrystalReportViewer1.ReportSource = rptTest1;


           // Exporting it as a PDf
              try
    {
        ExportOptions CrExportOptions;
        DiskFileDestinationOptions CrDiskFileDestinationOptions = new DiskFileDestinationOptions();
        PdfRtfWordFormatOptions CrFormatTypeOptions = new PdfRtfWordFormatOptions();
        CrDiskFileDestinationOptions.DiskFileName = Server.MapPath("~/Brochures/XMLReport.pdf");
        CrExportOptions = rptTest1.ExportOptions;
        {
            CrExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
            CrExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
            CrExportOptions.DestinationOptions = CrDiskFileDestinationOptions;
            CrExportOptions.FormatOptions = CrFormatTypeOptions;
        }
        rptTest1.Export();
    }
    catch (Exception ex)
    {

    }
}

public class rptTest
{
    public static DataTable ImageTable(string ImageFile)
    {
        Image ds = new Image();
        DataTable data = new DataTable();
        DataRow row;
        data.TableName = "Images";
        data.Columns.Add("Image", System.Type.GetType("System.Byte[]"));
        FileStream fs = new FileStream(ImageFile, FileMode.Open);
        BinaryReader br = new BinaryReader(fs);
        row = data.NewRow();
        row[0] = br.ReadBytes(Convert.ToInt32(br.BaseStream.Length));
        data.Rows.Add(row);
        br = null;
        fs.Close();
        fs = null;
     //  ds.Tables[0].Merge(data);
        return data;

    }
}

}


I had the same problem,this code should work

TableLogOnInfos crtableLogoninfos = new TableLogOnInfos()
TableLogOnInfo crtableLogoninfo = new TableLogOnInfo();
var connectionInfo = new ConnectionInfo();
connectionInfo.ServerName = "157.182.x.xxx";
connectionInfo.DatabaseName = "xxxx";
connectionInfo.Password = "xxxx";
connectionInfo.UserID = "xxxx";
connectionInfo.Type = ConnectionInfoType.SQL;
for (int i = 0; i < CrystalReportViewer1.LogOnInfo.Count; i++)
  {
      CrystalReportViewer1.LogOnInfo[i].ConnectionInfo = connectionInfo;
  }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜