如何在C#中禁用登录提示晶体报告 [英] How to disable login prompt crystal Report in C#

查看:59
本文介绍了如何在C#中禁用登录提示晶体报告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码,但它仍然让我登录失败

This is my code, but it still give me login Failed

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CrystalDecisions.Shared;
using CrystalDecisions.CrystalReports.Engine;
using System.IO;



namespace StockManagementSystem
{
    public partial class NameReport : Form
    {
        public NameReport()
        {
            InitializeComponent();
        }

        private void NameReport_Load(object sender, EventArgs e)
        { }

        private void crystalReportViewer1_Load(object sender, EventArgs e)
        { }

        private void button1_Click(object sender, EventArgs e)
        {
            ReportDocument report = new ReportDocument();
            TableLogOnInfos crtableLogoninfos = new TableLogOnInfos();
            TableLogOnInfo crtableLogoninfo = new TableLogOnInfo();

            Tables CrTables;
            report.Load("CrystalReport1.rpt");
            ConnectionInfo crConnectionInfo = new ConnectionInfo();
            report.Load("CrystalReport1.rpt");
            crConnectionInfo.ServerName = @".\SQLEXPRESS";
            crConnectionInfo.DatabaseName = "Stock";
            crConnectionInfo.UserID = "Reem";
            crConnectionInfo.Password = "123";

            CrTables = report.Database.Tables;
            foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables)
            {
                crtableLogoninfo = CrTable.LogOnInfo;
                crtableLogoninfo.ConnectionInfo = crConnectionInfo;
                CrTable.ApplyLogOnInfo(crtableLogoninfo);
            }
        }
    } 
       
 }

任何帮助!!!!!!!!!

Any help!!!!!!!!!

推荐答案

从您的评论
Reem94写道:

我没有数据库的用户名和密码,我只是写了任何要保存为用户名和密码的东西,因为我不知道从哪里可以得到它,对于servername和databasename是的我确定。对于数据源,我使用水晶报表向导,并在其中使用数据集。

I don't have a username and password for the database, I just wrote anything to be saved as username and password because i don't know from where i can get it, for the servername and databasename yes I am sure of it. for the datasource, i use a crystal report wizard and I use a Dataset in it.

您可能需要使用集成安全性。尝试

You probably need to use Integrated Security then. Try

report.DataSourceConnections[0].SetConnection(@".\SQLEXPRESS", "Stock", true);

report.DataSourceConnections[0].IntegratedSecurity = true;

并摆脱

crConnectionInfo.UserID = "Reem";
crConnectionInfo.Password = "123";



如果你提供了不正确的凭证(你有),那么你每次都会得到登录对话框。



编辑 - 这里是 SAP文档 [ ^ ]



编辑2 - 尝试类似......


If you provide incorrect credentials (which you have) then you will get the logon dialog every time.

Edit - here's a link to the SAP documentation[^]

Edit 2 - Try something like ...

ReportDocument report = new ReportDocument();
TableLogOnInfos crtableLogoninfos = new TableLogOnInfos();
TableLogOnInfo crtableLogoninfo = new TableLogOnInfo();
Tables CrTables;
 
report.DataSourceConnections[0].SetConnection(@".\SQLEXPRESS", "Stock", true);
report.Load("CrystalReport1.rpt");

...





编辑3 - 仍然无效。显然你也可以尝试



Edit 3 - still not working. Apparently you can also try

report.Database.Tables[0].LogOnInfo.ConnectionInfo.ServerName = @".\SQLEXPRESS";
report.Database.Tables[0].LogOnInfo.ConnectionInfo.DatabaseName = "Stock";
report.Database.Tables[0].LogOnInfo.ConnectionInfo.IntegratedSecurity = True;
CrystalDecisions.Shared.TableLogOnInfo tLogonInfo = New CrystalDecisions.Shared.TableLogOnInfo();
tLogonInfo.ConnectionInfo = rpt.Database.Tables[0].LogOnInfo.ConnectionInfo;
report.Database.Tables[0].ApplyLogOnInfo(tLogonInfo);

警告 - 我自己也没试过(也没有我可以)

Caveat - I haven't tried this myself (nor can I)


这篇关于如何在C#中禁用登录提示晶体报告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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