http://expert.csdn.net/Expert/topic/1900/1900717.xml?temp=2.103823E-02

解决方案 »

  1.   

    你用的推模式,不用指定登录信息的,重新做一下DATASET和StockReport报表
      

  2.   

    CrystalDecisions.CrystalReports.Engine.LogOnException:  登录失败。  
     
    ---------------------------------------------------------------  
     
    在报表的cs文件中,加上数据库连接。  
    ---------------------------------------------------------------  
     
    1.TableLogonInfo  
     
    .使用TableLogonInfo  
    Dim  ReportDoc  As  New  ReportDocument()  
    Dim  logonInfo  As  New  TableLogonInfo  
    Dim  table  As  table  
    ReportDoc.Load("C:\Rpts\publish.rpt")  
    For  Each  table  IN  ReportDoc.DataBase.Tables  
                   logonInfo=  table.LogonInfo  
                   with  logonInfo.connectioninfo  
                       .serverName=  "Localhost"  
                       .Databasename=  "pubs"  
                       .UserID=  "sa"  
                       .Password=""  
                   End  With  
                   table.applyLogonInfo(logonInfo)  
    next  table  
    Crviewer.reportsource=  reportDoc  
    2.如果是多個相關表格生成的報表,最好以存儲過程為數據源建立報表
      

  3.   

    代码放在 Page_load 事件里!
    试试 info.ConnectionInfo.ServerName =  "Localhost"
    用户名和密码的正确性再确定一下!
    ——————————————————————————————————————
    调试成功后,可以考虑:
    将“数据库连接信息”存放在 web.config 配置文件,容易维护
    ——————————————————————————————————————
    using CrystalDecisions.Shared ; //负责解释TableLogOnInfo类
    using CrystalDecisions.CrystalReports.Engine ; //负责解释ReportDocument类private void Page_Load(object sender, System.EventArgs e)
    {
    TableLogOnInfo logOnInfo = new TableLogOnInfo ();
    //这里必须事先申明一个ReportDocument对象 Report,同时加载数据报表
    ReportDocument oRpt = new ReportDocument();
    //获取.rpt文件真实路径
    string path;
    path=Server.MapPath ("cr.rpt");
    oRpt.Load (path);//从web.config中获取logOnInfo参数信息
    string a,b,c,d;
    //获取ServerName
    a=System.Configuration.ConfigurationSettings.AppSettings ["servername"];
    //获取DatabaseName
    b=System.Configuration.ConfigurationSettings.AppSettings ["database"];
    //获取UserId
    c=System.Configuration.ConfigurationSettings.AppSettings ["userid"];
    //获取password
    d=System.Configuration.ConfigurationSettings.AppSettings ["pass"];
    //设置logOnInfo参数
    logOnInfo.ConnectionInfo.ServerName = a;
    logOnInfo.ConnectionInfo.DatabaseName = b;
    logOnInfo.ConnectionInfo.UserID = c;
    logOnInfo.ConnectionInfo.Password = d;oRpt.Database .Tables [0].ApplyLogOnInfo (logOnInfo);//建立.rpt文件与CryStalReportviewer文件之间的连接
    CrystalReportViewer1.ReportSource = oRpt;DataBind();
    }