避免水晶报告用户名和密码 [英] Avoiding crystal report user name and password

查看:72
本文介绍了避免水晶报告用户名和密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用以下代码生成我的报告,它可以正常工作。但报告一直要求输入用户名和密码。我该如何避免这种情况。请帮助我谢谢。

 private void btnshow_Click(object sender,EventArgs e)
{

SqlConnection conn = new SqlConnection(ConfigurationSettings .AppSettings
[ConnectionString]);
conn.ConnectionString =数据源= USER-PC;初始目录= MUCGPROJECT;用户
ID = sa;密码=迈克;


SqlCommand cmd = new SqlCommand(string.Format(SELECT * FROM tblCollectorsRegistration
WHERE Collectorid ='{0}',this.txtCollectorid.Text),conn) ;
conn.Open();
SqlDataReader dr = cmd.ExecuteReader();

if(dr.HasRows)
{
conn.Close();
DataTable tbl = new DataTable();
conn.Open();
SqlDataAdapter adp = new SqlDataAdapter(SELECT Collectorid,Title,Surname,Firstname,
Middlename,Gender,Dateofbirth,Ethnic,Religion,Maritalstatus,
Spousename,Telephone,Postaladdress,Residentialaddress,Hometownaddress
来自tblCollectorsRegistration WHERE Collectorid ='+
this.txtCollectorid.Text +',conn);

adp.Fill(tbl);
rptCollectorindividual objRpt = new rptCollectorindividual();
objRpt.Database.Tables [0] .SetDataSource(tbl);
crystalReportViewer1.ReportSource = objRpt;
crystalReportViewer1.Refresh();
}
其他
{
// Id已经存在
MessageBox.Show(收集者ID不存在);
返回;

}
}

解决方案

raeeschaudhary在评论中的答案很好,但可能不是是问题。如果您是Crystal的新手,您是否确认报告和子报告中的所有连接都指向具有相同登录名的同一个数据库?如果是这样,如果raeeschaudhary的答案没有帮助,报告的年龄会有多大?在非常旧的报告中动态更新连接数据存在问题,但有一个解决方案,您可以在这里阅读: HTTP:// SCN .sap.com /社区/水晶报表换视觉工作室/博客/ 2011/09/02 /时使用的,该替换连接法,使用最水晶报表或 - INPROC -ras-sdk-for-net


ReportDocument r = new ReportDocument

r.Load(path);

ConnectionInfo connectionInfo = new ConnectionInfo();

connectionInfo.DatabaseName =dbname;

connectionInfo.UserID =userid;

connectionInfo.Password =pwd;

SetDBLogonForReport(connect ionInfo,r);

crystalReportViewer1.ReportSource = r;

crystalReportViewer1.RefreshReport();


    u  已添加 使用 这些   statement   as   headers  
使用 CrystalDecisions CrystalReports .Engine;使用 CrystalDecisions 。$
使用 CrystalDecisions Windows 者,恕不;


Am using the code below to generate my report and it works alright. but the report keeps asking for username and password. how do i avoid this. please help me out thanks.

private void btnshow_Click(object sender, EventArgs e)
        { 
            
            SqlConnection conn = new SqlConnection(ConfigurationSettings.AppSettings   
            ["ConnectionString"]);
            conn.ConnectionString = "Data Source=USER-PC;Initial Catalog=MUCGPROJECT;User  
            ID=sa;Password=mike";
           
            
     SqlCommand cmd = new SqlCommand(string.Format("SELECT * FROM tblCollectorsRegistration     
            WHERE Collectorid='{0}'", this.txtCollectorid.Text), conn);
                conn.Open();
                SqlDataReader dr = cmd.ExecuteReader();
                
                if (dr.HasRows)
                {
                    conn.Close();
                    DataTable tbl = new DataTable();
                    conn.Open();
    SqlDataAdapter adp = new SqlDataAdapter("SELECT Collectorid, Title, Surname, Firstname, 
                    Middlename, Gender, Dateofbirth, Nationality, Religion, Maritalstatus,   
                    Spousename, Telephone, Postaladdress, Residentialaddress, Hometownaddress  
                    from tblCollectorsRegistration WHERE Collectorid = '" +     
                    this.txtCollectorid.Text + "'", conn);
                    
                    adp.Fill(tbl);
                    rptCollectorindividual objRpt = new rptCollectorindividual();
                    objRpt.Database.Tables[0].SetDataSource(tbl);
                    crystalReportViewer1.ReportSource = objRpt;
                    crystalReportViewer1.Refresh();
                }
                else
                {
                    // Id already present
                    MessageBox.Show("The Collector ID does not Exist");
                    return;
                   
                }
        }

解决方案

raeeschaudhary's answer in the comments is fine, but that might not be the problem. If you're a newbie to Crystal, have you verified that ALL your connections in both the report and subreport are pointing to the same DB with the same login? And if so, and if raeeschaudhary's answer doesn't help, how old are the reports? There are problems with dynamically updating connection data in very old reports, but there is a solution that you can read about here: http://scn.sap.com/community/crystal-reports-for-visual-studio/blog/2011/09/02/when-to-use-the-replace-connection-method-using-the-crystal-reports-or-inproc-ras-sdk-for-net


ReportDocument r=new ReportDocument
r.Load("path");
ConnectionInfo connectionInfo = new ConnectionInfo();
connectionInfo.DatabaseName = "dbname";
connectionInfo.UserID = "userid";
connectionInfo.Password = "pwd";
SetDBLogonForReport(connectionInfo, r);
crystalReportViewer1.ReportSource = r;
crystalReportViewer1.RefreshReport();


did u added using these three statement as headers
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using CrystalDecisions.Windows.Forms;


这篇关于避免水晶报告用户名和密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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