C#水晶报表:无法连接:登录参数不正确 [英] C# crystal reports : Unable to connect : Incorrect log on parameters

查看:87
本文介绍了C#水晶报表:无法连接:登录参数不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Visual Studio2008.在客户端计算机上运行项目时,尝试打印报告时出现此错误.这在我的机器上工作正常.
我已经在客户端计算机上安装了CR Runtime.
-------------------------------------------------- ----------------------------
Crystal Report Windows窗体查看器.

Error in File:C:\Users\Nuwan\AppData\Local\Temp\rptInvoice{C51266F3-E2EE-4A02-B5CF-12BCE727360C}.rpt:无法连接:错误的登录参数.

-------------------------------------------------- --------------------------------

这是我的代码部分.

-------------------------------------------------- ----------------------------------

I''m using Visual Studio 2008. When I run my project in client machine I''m getting this error, when try to print the report. This is working fine in my machine.
I have installed CR Runtime in client machine.
------------------------------------------------------------------------------
Crystal Report Windows Forms Viewer.

Error in File:C:\Users\Nuwan\AppData\Local\Temp\rptInvoice{C51266F3-E2EE-4A02-B5CF-12BCE727360C}.rpt: Unable to connect : incorrect logon parameters.

----------------------------------------------------------------------------------

This is my code part.

------------------------------------------------------------------------------------

try
{

    ReportDocument cryRpt = new ReportDocument();
    cryRpt.Load(@"rptDNote.rpt");
    ParameterFieldDefinitions crParameterFieldDefinitions;
    ParameterFieldDefinition crParameterFieldDefinition;
    ParameterValues crParameterValues = new ParameterValues();
    ParameterDiscreteValue crParameterDiscreteValue = new ParameterDiscreteValue();

    crParameterDiscreteValue.Value = int.Parse(cmbInvoNo.Text);
    crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields;
    crParameterFieldDefinition = crParameterFieldDefinitions["InvoNo"];
    crParameterValues = crParameterFieldDefinition.CurrentValues;

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

    crystalReportViewer1.Refresh();
    crystalReportViewer1.ReportSource = cryRpt;
    crystalReportViewer1.PrintReport();
}
catch (Exception ex)
{
    MessageBox.Show(ex.ToString());
}

推荐答案

由于服务器与开发服务器和客户端服务器不同.您应该指示水晶报表对象使用其他连接信息.尝试使用此代码.我建议将凭据存储在您的应用程序配置中.希望对您有所帮助.

Since the server is different from your development server and the client server. You should instruct you crystal report object to use different connection info. Try to use this code. I suggest to store credential on your app config. I hope this helps.

ConnectionInfo crConnectionInfo = new ConnectionInfo();
crConnectionInfo.ServerName = "YOUR SERVER NAME";
crConnectionInfo.DatabaseName = "YOUR DATABASE NAME";
crConnectionInfo.UserID = "YOUR DATABASE USERNAME";
crConnectionInfo.Password = "YOUR DATABASE PASSWORD";
CrTables = cryRpt.Database.Tables ;
foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables)
{
    crtableLogoninfo = CrTable.LogOnInfo;
    crtableLogoninfo.ConnectionInfo = crConnectionInfo;
    CrTable.ApplyLogOnInfo(crtableLogoninfo);
}


这篇关于C#水晶报表:无法连接:登录参数不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆