ASP.NET中的水晶报告集成安全性

时间:2017-07-02 05:31:05

标签: c# crystal-reports

这是我的代码,我不知道如何在report.SetDatabaseLogon中设置集成安全性。没有错误,但报告没有加载到网络表单中。

void GetUsers()
{
    ReportDocument report = new ReportDocument();
    report.Load(Server.MapPath("~/Admin/Reports/rptUsers.rpt"));
    report.SetDatabaseLogon("(localdb)", "CAPROJ2");
    report.SetParameterValue("User", "Arteezy");

    crvUsers.ReportSource = report;
    crvUsers.DataBind();
}
编辑:我忘了包含我的服务器名是(localdb)\ SQL,但我试图使用它,但它显示“\”无法识别的转义序列。

2 个答案:

答案 0 :(得分:0)

根据SAP论坛,您可以尝试:

report.DataSourceConnections[0].IntegratedSecurity = true;
// and/or 
report.DataSourceConnections[0].SetConnection("(localdb)", "CAPROJ2", true);

答案 1 :(得分:0)

    // Create new report document
    var rd = new ReportDocument();

    // Construct full filename pointing to rpt
    var reportFile = Path.Combine(Environment.CurrentDirectory, @"Reports\CR\", rptFileName);

    // Load the rpt file
    rd.Load(reportFile);


    // Create connectionInfo object to override default rpt config info
    // Provide login information
    var crConnectionInfo = new ConnectionInfo();

    // In the form - "SERVER_NAME\\SQLEXPRESS"
    // In this example we store serverName, db, user and PW in config table
    // If userID config is not in config table, assume we will use Microsoft integrated security
    crConnectionInfo.ServerName   = serverName;
    crConnectionInfo.DatabaseName = databaseName;
    if (userID != null)
    {
        crConnectionInfo.UserID   = userID;
        crConnectionInfo.Password = password;
    }
    else
    {
        crConnectionInfo.IntegratedSecurity = true;
    }

    // For every table defined in rpt, override login info
    var CrTables = rd.Database.Tables;
    foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables)
    {
        var crtableLogoninfo = CrTable.LogOnInfo;
        crtableLogoninfo.ConnectionInfo = crConnectionInfo;
        CrTable.ApplyLogOnInfo(crtableLogoninfo);
    }
    // If this is a web service and you want to return a PDF ...
    var s = rd.ExportToStream(ExportFormatType.PortableDocFormat);