日期:2014-05-20  浏览次数:20973 次

水晶报表每次需要输入用户名密码
我用c#做一个C/S结构的程序,用到水晶报表打印,水晶报表的数据源用的是ODBC,ODBC数据源连接的是远程服务器(SQL SERVER 2000),问题出在每次打印时都弹出数据库登录窗口,要输入UID,和PWD。需要修改那些东西实现不弹出数据库登录窗口。
提示我连接本地数据库时不弹出这个登录窗口。


还有远程连接SQL SERVER 2000是不是必须有个用户名?

------解决方案--------------------
我用的是sql2005数据库,如果你的报表没有数据连接,没有参数的话,不会弹让你输入用户名和密码,后来做了一下改动,就没有了,具体是这样做的:


1、继承这个类,加入新的属性和方法
C# code

public class TLReportDocument:ReportDocument
    {
        //报表属性
        public string ch_ReportName;
        public string en_ReportName;
        public string ReportPath;
        public string ExportPath;     
        public bool exportIfModify;



        //报表与数据库的连接
        public string ReportServerName;
        public string ReportDataBaseName;
        public string UserID;
        public string Password;
   
        public TLReportDocument()
        {          

        }

        //加载报表
        public ReportDocument Load()
        {
            this.Load(this.ReportPath + this.en_ReportName);
            return this;
        }


        //连接数据库
        public void LoginDataBase()
        {
            Database crDatabase;
            CrystalDecisions.CrystalReports.Engine.Tables crTables;
            TableLogOnInfo crTableLogOnInfo;
            ConnectionInfo crConnectionInfo;

            crConnectionInfo = new ConnectionInfo();
            crConnectionInfo.ServerName = this.ReportServerName;
            crConnectionInfo.DatabaseName = this.ReportDataBaseName;
            crConnectionInfo.UserID = this.UserID;
            crConnectionInfo.Password = this.Password;

            //取得报表连接的表数
            crDatabase = this.Database;
            crTables = crDatabase.Tables;
            //设置报表每z张表的连接
            foreach (CrystalDecisions.CrystalReports.Engine.Table crTable in crTables)
            {
                crTableLogOnInfo = crTable.LogOnInfo;
                crTableLogOnInfo.ConnectionInfo = crConnectionInfo;
                crTable.ApplyLogOnInfo(crTableLogOnInfo);
            }
        }
    }