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.如果是多個相關表格生成的報表,最好以存儲過程為數據源建立報表
代码放在 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();
}

解决方案 »

  1.   

    大家一起到这里支持一下!!!
    http://expert.csdn.net/Expert/TopicView1.asp?id=2291055
    CSDN 开个 Crystal Report 版吧!!!&&&我与水晶报表……
    haibodotnet 海波.NET
      

  2.   

    我不想用ReportDocument 定义变量这种方式
    因为用这种方式oRpt.Load (path);
    容易出错。
    我用上面我采用的方式,单表的时候是正确的
    况且那些登陆信息,在数据库的连接字符里面都写出来了就是在sConn中。