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();
}
---------------------------------------------------------------
在报表的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();
}
http://expert.csdn.net/Expert/TopicView1.asp?id=2291055
CSDN 开个 Crystal Report 版吧!!!&&&我与水晶报表……
haibodotnet 海波.NET
http://expert.csdn.net/Expert/TopicView1.asp?id=2291055
CSDN 开个 Crystal Report 版吧!!!&&&我与水晶报表……
haibodotnet 海波.NET
实在不好意思,我就是按你的方法做的啊,还是登录失败!麻烦你具体帮我分析分析,你的帖我已经响应了。强烈支持,也支持你当斑竹,但还是帮我把问题解决了先。我在winform下用报表自认为还是比较熟悉的,可在webform中,连看都看不见。费解。
CrystalDecisions.CrystalReports.Engine.LogOnException: 登录失败。
---------------------------------------------------------------
原因一: NTFS 文件夹权限的问题!
文件夹:
VS.NET Crystal Reports:
C:\Program Files\Microsoft Visual Studio .NET\Crystal Reports\Viewers
Crystal Reports 9.2:
C:\Program Files\Common Files\Crystal Decisions\2.0\crystalreportviewers
设置上述文件夹的“安全”,即NTFS 文件夹权限的问题!
1、添加当前用户,比如 Administrator,,权限“写入”;
2、添加用户 ASPNET,权限“写入”!
---------------------------------------------------------------
原因二:数据库登录问题
在报表的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();
}