当从本地机器转移到服务器时,Crystal需要更多的信息来登录数据库
本文关键字:信息 数据库 登录 Crystal 机器 转移 服务器 | 更新日期: 2023-09-27 18:05:58
我知道这已经被其他用户发布之前,我已经尝试查看所有的答案已经回答并尝试了一切,但似乎没有工作。所以在这里我再次张贴问题与我的代码....请帮帮我……这在本地机器上工作得很好,并且生成了水晶报告,但是当我把它放在服务器上时,它会询问数据库的进一步信息,如服务器名称,用户名,密码……尝试了所有的方法,但都没有用....请帮助…
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;
}
}
}
我有同样的问题,这段代码应该工作
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;
}