水晶报表学习记录之二(数据库登陆问题)

在使用到CrystalReportViewer的时候,有个选项是关于数据库连接的,每次在Web页面浏览的时候只要有关于数据库相关的,都首先需要先登陆数据库,那么我们能不能把这个讨厌的窗口去掉了呢?直接每次打开页面的时候就通过认证,然后就可以直接显示报表数据。

Default.aspx
-----------------------------------------------------------------------
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %>
<%@ Register Assembly="CrystalDecisions.Web, Version=10.2.3600.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" Namespace="CrystalDecisions.Web" TagPrefix="CR" %>



    无标题页
            rel="stylesheet" type="text/css" />


   


   

       
   

   



--------------------------------------------------------------------
Default.aspx.cs
--------------------------------------------------------------------
using CrystalDecisions.Shared;
using CrystalDecisions.ReportSource;
using CrystalDecisions.CrystalReports.Engine;

private void Page_Init(object sender, EventArgs e)
    {
        ConfigCrystalReports();
    }
    private void ConfigCrystalReports()
    {
        ConnectionInfo ConnectionInfo = new ConnectionInfo();
        ConnectionInfo.ServerName = "服务器名称或IP";
        ConnectionInfo.DatabaseName = "数据库名称";
        ConnectionInfo.UserID = "登陆帐号";
        ConnectionInfo.Password = "登陆密码";
        string ReportPath = Server.MapPath("CrystalReport1.rpt(这个是你的报表名称)");
        CrystalReportViewer1.ReportSource = ReportPath;
        SetDbLoginForReport(ConnectionInfo);
    }

    private void SetDbLoginForReport(ConnectionInfo ConnectionInfo)
    {
        TableLogOnInfos tableLogOnInfos = CrystalReportViewer1.LogOnInfo;
        foreach (TableLogOnInfo tableLogOnInfo in tableLogOnInfos)
        {
            tableLogOnInfo.ConnectionInfo = ConnectionInfo;
        }
    }

转载于:https://www.cnblogs.com/Apollo/archive/2006/02/27/338604.html

你可能感兴趣的:(数据库,xhtml,c#)