Crystal Report登录失败

时间:2012-11-06 08:54:48

标签: c# crystal-reports

我想打印我的报告,但是当我设置server =(IP)\ SQLEXPRESS总是无法登录时,在管理工作室工作正常。如果我设置server =。\ SQLEXPRESS它正在工作。为什么我不能使用ip连接报告到数据库?

public class PrintService : IPrintService
{
    readonly ReportDocument _reportDocument = new ReportDocument();

    private readonly string _reportPath = ConfigurationManager.AppSettings["ReportPath"];
    private readonly string _reportUser = ConfigurationManager.AppSettings["ReportUser"];
    private readonly string _reportPassword = ConfigurationManager.AppSettings["ReportPassword"];
    private readonly string _reportServer = ConfigurationManager.AppSettings["ReportServer"];
    private readonly string _reportDatabase = ConfigurationManager.AppSettings["ReportDatabase"];
    private readonly string _spbuNumber = ConfigurationManager.AppSettings["SPBUNumber"];
    private readonly string _spbuAddress = ConfigurationManager.AppSettings["SPBUAddress"];
    private readonly string _spbuPhone = ConfigurationManager.AppSettings["SPBUPhone"];

    public void Print(string number, string reportName)
    {
        var path = _reportPath + reportName;
        _reportDocument.Load(path);
        _reportDocument.SetDatabaseLogon(_reportUser, _reportPassword, _reportServer, _reportDatabase);
        _reportDocument.SetParameterValue("@Number", number);
        _reportDocument.SetParameterValue("@Location", _spbuNumber );
        _reportDocument.SetParameterValue("@Address", _spbuAddress);
        _reportDocument.SetParameterValue("@Phone", _spbuPhone);
        var print = new PrintDocument();
        _reportDocument.PrintOptions.PrinterName = print.PrinterSettings.PrinterName;
        _reportDocument.PrintOptions.PaperSize = (PaperSize) print.PrinterSettings.DefaultPageSettings.PaperSize.RawKind;
        _reportDocument.PrintToPrinter(1, false, 1, 1);
    }
}

谢谢:)

2 个答案:

答案 0 :(得分:0)

IS(IP)是服务器名称或IP地址,如果Ip是服务器名称,则删除括号。或者使用该服务器的直接IP地址。

答案 1 :(得分:0)

要在运行时加载报表,在客户端PC上,我需要删除连接字符串以查找客户端的本地服务器名称。我尝试了不同的方法来改变水晶报表的登录连接,但只有这对我有用。这是最新的13.0.9.1312.Cortez_CR4VS版本,WPF中的Windows窗体版本。 在此代码中,prepap是完整的Crystal报表名称,包括路径和dbName,只是附加的SQL数据库的名称。 csName来自app.config:string from add name。新连接将保存在报告中。

ReportDocument doc = new ReportDocument();
String CS = (String)ConfigurationManager.ConnectionStrings[csName].ConnectionString;
doc.Load(prerap);
String DS = CS.Substring(12 + CS.IndexOf("data source"), CS.IndexOf("SQLEXPRESS") - CS.IndexOf("data source") - 2);
            if (doc.DataSourceConnections[0].ServerName != DS)
            {
                for(int i=0;i<doc.DataSourceConnections.Count;i++) 
                {
                    doc.DataSourceConnections[i].SetConnection(DS, dbName, true);               
                }

                doc.SaveAs(prerap);

            }