因为在开发过程中碰到一个难题.   水晶报表开发时,  在一张报表里用到了子父报表,  
 
         在本地调试时可以成功, 但发布到服务器时, 却会出现类似于:你请求需要更多的信息, 然后就要你输入数据库的用户名和密码
 
      
         以下是我在网络上面查出来的答案:
 
         1  我以前遇到过的问题和你类似!
            出现个对话框要你连接数据库!
            我后来是把数据专家的连接都改为SQLOLEDB的方式;但连接要用同一个连接,就是你的所有报表都要用第一次新建的链接,不能再去新建一个。

解决方案 »

  1.   

        <div>    
        <CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server" 
            AutoDataBind="true" />    
        </div>    protected void Page_Load(object sender, EventArgs e)
        {
            // 在此处放置用户代码以初始化页面 
            TableLogOnInfo logOnInfo = new TableLogOnInfo();
            ReportDocument oRpt = new ReportDocument();
           // string RptDir = "f:\\bbs\\test\\crystal\\crystalreport1.rpt"; //crystalreport1.rpt文件所在的绝对路径 
            oRpt.Load(Server.MapPath("SR1.rpt"));        //设置logOnInfo参数,注意这里如果不设?编译时最容易出现“登陆失败”的错误! 
            logOnInfo.ConnectionInfo.ServerName = "172.26.1.128";
            logOnInfo.ConnectionInfo.DatabaseName = "TEST";
            logOnInfo.ConnectionInfo.UserID = "sa";
            logOnInfo.ConnectionInfo.Password = "sa";
            oRpt.Database.Tables[0].ApplyLogOnInfo(logOnInfo);        //建立.rpt文件与CryStalReportviewer文件之间的连接 
            CrystalReportViewer1.ReportSource = oRpt;
        }
      

  2.   

    protected void CrystalReportViewer1_Init(object sender, EventArgs e)
        {
            ForCrystalReport();
        }    protected void ForCrystalReport()
        {
            ReportDocument doc = new ReportDocument();
            doc.Load(Server.MapPath("SR1.rpt"));   //载入水晶报表
            TableLogOnInfo info = new TableLogOnInfo();  //这个设定可以免去登陆提示,可以自动登录,为报表中的表设置连接信息
            info.ConnectionInfo.DatabaseName = "SR";  //设定数据库
            info.ConnectionInfo.UserID = "sa";  //数据库登录名
            info.ConnectionInfo.ServerName = "172.25.1.286";  //数据库所在服务器IP地址
            info.ConnectionInfo.Password = "*******"; //密码
            foreach (CrystalDecisions.CrystalReports.Engine.Table table in doc.Database.Tables)  //设置每个表的登录信息
            {
                table.ApplyLogOnInfo(info);  //将连接信息用于表
            }
            this.CrystalReportViewer1.ReportSource = doc;
        }
    <%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %><%@ Register Assembly="CrystalDecisions.Web, Version=10.5.3700.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>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
        <CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server" 
                AutoDataBind="true" DisplayGroupTree="False" DisplayToolbar="False" 
                oninit="CrystalReportViewer1_Init" />
        </div>    
        </form>
    </body>
    </html>