Dim loginfo As TableLogOnInfo = New TableLogOnInfo()
      Dim oRpt As ReportDocument = New ReportDocument()
      Dim rpt_filename = Server.MapPath("rpt文件路径的相对路径")
      oRpt.Load(fs_filename)
      loginfo.ConnectionInfo.ServerName = "***" '服务名
      loginfo.ConnectionInfo.DatabaseName = "***" '库
      loginfo.ConnectionInfo.UserID = "***" '用户名
      loginfo.ConnectionInfo.Password = "***" '
      oRpt.Database.Tables(0).ApplyLogOnInfo(loginfo)
      crv_aa.ReportSource = oRpt

解决方案 »

  1.   

    彻底解决 CrystalReports 登录失败问题(海波.NET)
    问题:
    CrystalReports 登录失败
    ---------------------------------------------------------------  
    原因一: 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();
    }
      

  2.   

    如果文件采用Fat32格式,是不是不存在楼上的第一个问题?
      

  3.   

    彻底解决 CrystalReports 登录失败问题(海波.NET,更新:2003-10-16-3)
    ---------------------------------------------------------------
    目录:
    一、Crystal Reports 9 最新补丁下载(搜集:海波.NET)
    二、问题:CrystalReports 登录失败
    三、原因一: NTFS 文件夹权限的问题!
    四、原因二:数据库登录问题
    五、部署到其它计算机,产生问题:连接失败。错误的登录参数。
    六、安全之道:crystalreport 的集成认证如何与NT(2K)SERVER集成??
    ---------------------------------------------------------------
    问题:
    CrystalReports 登录失败
    LogOnException
    --------------------------------------------------------------- 
    Crystal Reports 9 最新补丁下载
    (1)Crystal Reports 9 Database and Export Drivers Monthly Hot Fix
    http://support.crystaldecisions.com/communityCS/FilesAndUpdates/cr90dbexwin_en.zip.asp?recDnlReq=Record&dnlPath=cr90dbexwin_en.zip
    (2)Crystal Reports 9 Developer Files Monthly Hot Fix
    http://support.crystaldecisions.com/communityCS/FilesAndUpdates/cr90devwin_en.zip.asp?recDnlReq=Record&dnlPath=cr90devwin_en.zip
    (3)Crystal Reports 9.0 Main Program Files Monthly Hot Fix
    http://support.crystaldecisions.com/communityCS/FilesAndUpdates/cr90mainwin_en.zip.asp?recDnlReq=Record&dnlPath=cr90mainwin_en.zip 
    --------------------------------------------------------------- 
    原因一: 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、SYSTEM、匿名用户(通常为 IUSR_MACHINENAME)、经过身份验证的请求用户添加“写入”权限!
    ---------------------------------------------------------------
    原因二:数据库登录问题
    PULL 模式下:
    在报表的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、调试成功后,可以考虑:
    将“数据库连接信息”存放在 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();
    }
    ---------------------------------------------------------------
    原因三、PUSH 模式不需要设置 TableLogOnInfo!!!
    因为数据源是 DataSet,不是数据库!!!
    ---------------------------------------------------------------
    问题:
    部署到其它计算机,产生问题:连接失败。错误的登录参数。
    在开发机(2000)上运行,一切正常;移植到生产机(2003),就报错。错误提示:连接失败。错误的登录参数。
    解决方案:
    部署包少了点东西:
    Crystal_Database_Access2003.msm
    Crystal_Database_Access2003_chs.msm
    这两个合并模块包含各种连接数据源的驱动。所以少了它,就老是提示登录失败(这种提示是不是很莫名其妙?)
    ---------------------------------------------------------------
    附件:
    海波.NET
    问题:
    安全之道:crystalreport 的集成认证如何与NT(2K)SERVER集成??
    ——————————————————————————————————————
    安全三要素:
    模拟,验证,授权
    ——————————————————————————————————————
    如果运行 ASP.NET 程序,还需要为 ASPNET 账号——运行 ASP.NET 模拟的账号,做下述设置:1、通过 Web 访问服务器,访问者默认“模拟”的是——Internet 来宾帐号,账号名:IUSR_计算机名;
    2、“IUSR_计算机名”账号要访问 SQL SERVER,必须为该帐号建立“登录”(验证也!);
    3、并授予“服务器角色”和“数据库访问许可”、“数据库角色”(授权也)!
    ——————————————————————————————————————
    参考:
    1、匿名访问 Web 所模拟的账号
    账号名:IUSR_计算机名
    全名:Internet 来宾帐号
    描述:匿名访问 Internet 信息服务的内置帐号2、运行 ASP.NET 模拟的账号
    账号名:ASPNET
    全名:aspnet_wp account
    描述:运行 ASP.NET 工作进程的账号
      

  4.   

    彻底解决 CrystalReports 登录失败问题(海波.NET,更新:2003-10-16-3)
    ---------------------------------------------------------------
    目录:
    一、Crystal Reports 9 最新补丁下载(搜集:海波.NET)
    二、问题:CrystalReports 登录失败
    三、原因一: NTFS 文件夹权限的问题!
    四、原因二:数据库登录问题
    五、部署到其它计算机,产生问题:连接失败。错误的登录参数。
    六、安全之道:crystalreport 的集成认证如何与NT(2K)SERVER集成??
    ---------------------------------------------------------------
    问题:
    CrystalReports 登录失败
    LogOnException
    --------------------------------------------------------------- 
    Crystal Reports 9 最新补丁下载
    (1)Crystal Reports 9 Database and Export Drivers Monthly Hot Fix
    http://support.crystaldecisions.com/communityCS/FilesAndUpdates/cr90dbexwin_en.zip.asp?recDnlReq=Record&dnlPath=cr90dbexwin_en.zip
    (2)Crystal Reports 9 Developer Files Monthly Hot Fix
    http://support.crystaldecisions.com/communityCS/FilesAndUpdates/cr90devwin_en.zip.asp?recDnlReq=Record&dnlPath=cr90devwin_en.zip
    (3)Crystal Reports 9.0 Main Program Files Monthly Hot Fix
    http://support.crystaldecisions.com/communityCS/FilesAndUpdates/cr90mainwin_en.zip.asp?recDnlReq=Record&dnlPath=cr90mainwin_en.zip 
    --------------------------------------------------------------- 
    原因一: 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、SYSTEM、匿名用户(通常为 IUSR_MACHINENAME)、经过身份验证的请求用户添加“写入”权限!
    ---------------------------------------------------------------
    原因二:数据库登录问题
    PULL 模式下:
    在报表的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、调试成功后,可以考虑:
    将“数据库连接信息”存放在 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();
    }
    ---------------------------------------------------------------
    原因三、PUSH 模式不需要设置 TableLogOnInfo!!!
    因为数据源是 DataSet,不是数据库!!!
    ---------------------------------------------------------------
    问题:
    部署到其它计算机,产生问题:连接失败。错误的登录参数。
    在开发机(2000)上运行,一切正常;移植到生产机(2003),就报错。错误提示:连接失败。错误的登录参数。
    解决方案:
    部署包少了点东西:
    Crystal_Database_Access2003.msm
    Crystal_Database_Access2003_chs.msm
    这两个合并模块包含各种连接数据源的驱动。所以少了它,就老是提示登录失败(这种提示是不是很莫名其妙?)
    ---------------------------------------------------------------
    附件:
    海波.NET
    问题:
    安全之道:crystalreport 的集成认证如何与NT(2K)SERVER集成??
    ——————————————————————————————————————
    安全三要素:
    模拟,验证,授权
    ——————————————————————————————————————
    如果运行 ASP.NET 程序,还需要为 ASPNET 账号——运行 ASP.NET 模拟的账号,做下述设置:1、通过 Web 访问服务器,访问者默认“模拟”的是——Internet 来宾帐号,账号名:IUSR_计算机名;
    2、“IUSR_计算机名”账号要访问 SQL SERVER,必须为该帐号建立“登录”(验证也!);
    3、并授予“服务器角色”和“数据库访问许可”、“数据库角色”(授权也)!
    ——————————————————————————————————————
    参考:
    1、匿名访问 Web 所模拟的账号
    账号名:IUSR_计算机名
    全名:Internet 来宾帐号
    描述:匿名访问 Internet 信息服务的内置帐号2、运行 ASP.NET 模拟的账号
    账号名:ASPNET
    全名:aspnet_wp account
    描述:运行 ASP.NET 工作进程的账号