C# 水晶报表询问用户名和密码

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13718270/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 09:33:16  来源:igfitidea点击:

Crystal report asking username and password

c#asp.netcrystal-reports-2010

提问by anonymizer

Every time I open my form that has a crystal report it always ask for username and password but i did not even use a username and password in my web application. I use integrated security in my web.config. How can I fix this problem?

每次我打开带有水晶报告的表单时,它总是要求输入用户名和密码,但我什至没有在我的 Web 应用程序中使用用户名和密码。我在 web.config 中使用了集成安全性。我该如何解决这个问题?

This is code:

这是代码:

            using System;
            using System.Collections.Generic;
            using System.Linq;
            using System.Web;
            using System.Web.UI;
            using System.Web.UI.WebControls;
            // FOR CRYSTAL REPORT
            using CrystalDecisions.CrystalReports.Engine;
            using CrystalDecisions.Shared;
            using System.Data;
            using System.Configuration;

            // FOR SQL CONNECTION
            using System.Data.Sql;
            using System.Data.SqlClient;
            using MediCard_Cooperative.App_Data;

            namespace MediCard_Cooperative.MediCard_Cooperative.Reports
            {
                public partial class rptTest : System.Web.UI.Page
                {
                    private SqlConnection connSQL;

                    protected void Page_Load(object sender, EventArgs e)
                    {
                        ReportDocument rptDoc = new ReportDocument();
                        dsMembers ds = new dsMembers();                     // .xsd or dataset filename
                        DataTable dt = new DataTable();

                        // Set the name of data table
                        dt.TableName = "Crystal Report Members";
                        dt = getAllData();                                  // calling 'getAllMembers' function
                        ds.Tables[0].Merge(dt);

                        // .rpt file path "../Reports/SimpleReports.rpt"
                        rptDoc.Load(Server.MapPath("../Reports/CrystalReports/ctrSample.rpt"));

                        //set dataset to the report viewer
                        rptDoc.SetDataSource(ds);
                        ctrViewerTest.ReportSource = rptDoc;
                    }

                    public DataTable getAllData()
                    {
                        try
                        {
                            using (connSQL = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["connstring"].ToString()))
                            {
                                using (SqlCommand cmd = new SqlCommand("usp_Test", connSQL))
                                {
                                    cmd.CommandType = CommandType.StoredProcedure;

                                    connSQL.Open();
                                    cmd.ExecuteNonQuery();

                                    using (SqlDataAdapter da = new SqlDataAdapter(cmd))
                                    {
                                        DataSet ds = new DataSet();

                                        da.Fill(ds, "dtTest");

                                        return ds.Tables[0];
                                    }

                                }

                            }

                        }
                        catch (Exception ex)
                        {
                            throw new Exception(ex.Message);
                        }
                    }
                }
            }

回答by Juvil

it is unable to find the dataset or the dataset used to design the report is different from the dataset passed, crystal report assumed you need to log in.

无法找到数据集或用于设计报表的数据集与传递的数据集不同,水晶报表假设您需要登录。

since you are not passing parameter to your sp, i think it would be better to directly let crystal report manage those. lesser code to maintain.

由于您没有将参数传递给您的 sp,我认为直接让 Crystal Report 管理这些会更好。要维护的代码较少。

回答by Sandeep

You will have to mention the database username and password through the ReportDocumentobject.

您将不得不通过ReportDocument对象提及数据库用户名和密码。

rptDoc.SetDatabaseLogon(username, password);

回答by sajanyamaha

you need to pass server credentials through code

您需要通过代码传递服务器凭据

rptDoc.SetDatabaseLogon(yourDatabaseServerUsername, yourDatabaseServerPassword);

something like

就像是

rptDoc.SetDatabaseLogon("sa", "123");

回答by Major

Open your crystal Report in C# or VB whatever you are using Then Go to Field Explorer and Right Click on Database Fields Like enter image description here

无论您使用什么,在 C# 或 VB 中打开您的水晶报表,然后转到字段资源管理器并右键单击数据库字段,例如 在此处输入图片说明

And Select Set Datasources Location...

并选择设置数据源位置...

A new Window will open... Expand the properties.

将打开一个新窗口... 展开属性。

enter image description here

在此处输入图片说明

Then Find the integrated Security It will Be False by default Change it to True

然后找到集成的Security 默认为False 改成True

Like

喜欢

enter image description here

在此处输入图片说明

回答by Ejaz Sarwar

rpt.SetDatabaseLogon("sureguide_admin", "ejaz661")

rpt.SetDatabaseLogon("sureguide_admin", "ejaz661")

ts working

正在工作

回答by Abdul Waheed

Dim myreport As New PurchaseInvoiceTest'Crystal Reports asks for authentication every time issue resolved by below line myreport.SetDatabaseLogon("sa", "abcdef@12345")

Dim myreport As New PurchaseInvoiceTest'Crystal Reports 每次通过以下行解决问题时都要求进行身份验证 myreport.SetDatabaseLogon("sa", "abcdef@12345")