水晶报表--数据库登陆问题(转载)

在使用到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" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>无标题页</title>
    <link href="/aspnet_client/System_Web/2_0_50727/CrystalReportWebFormViewer3/css/default.css"
        rel="stylesheet" type="text/css" />
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server" AutoDataBind="true" />
    </div>
    </form>
</body>
</html>
--------------------------------------------------------------------
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/gergro/archive/2006/09/01/492016.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值