Crystal reports, why is it asking for database login even after I provided the details?

后端 未结 4 1920
天涯浪人
天涯浪人 2020-12-18 08:36

I am generating a report, but the problem is even though I\'ve supplied credentials, when the form containing the CrystalReport opens up, it still asks me for them, and the

相关标签:
4条回答
  • 2020-12-18 08:44

    see my answer here regarding older version of SQL Native Client saved with the report file and disabled, insecure encryption protocols such as TLS 1.0 that causes what appears to be a login failure.

    0 讨论(0)
  • 2020-12-18 08:52

    Just create report object and add below link rptobj is crystalreport object and setdatabaselogin is method which take user id and password as a parameter.

    rptobj.setdatabaselogon(userid,password)

    0 讨论(0)
  • 2020-12-18 08:53

    We have lots of problems when we came to connect a crystal report to a different database to the one it was designed / created against. We ended up creating the following function to set it up correctly. It recursively sets the connection on all report tables and sub reports.

    Also I seem to remember we had problems if the report was designed with Integrated Windows Authentications, and run with a simple username and password. So we always made sure we designed the reports with a simple username and password connection to the database.

    private static void SetConnection(ReportDocument report, string databaseName, string serverName, string userName, string password)
    {
        foreach (Table table in report.Database.Tables)
        {
            if (table.Name != "Command")
            {
                SetTableConnectionInfo(table, databaseName, serverName, userName, password);
            }
        }
    
        foreach (ReportObject obj in report.ReportDefinition.ReportObjects)
        {
            if (obj.Kind != ReportObjectKind.SubreportObject)
            {
                return;
            }
    
            var subReport = (SubreportObject)obj;
            var subReportDocument = report.OpenSubreport(subReport.SubreportName);
            SetConnection(subReportDocument, databaseName, serverName, userName,  password);
        }
    }
    
    private static void SetTableConnectionInfo(Table table, string databaseName, string serverName, string userName, string password)
    {
        // Get the ConnectionInfo Object.
        var logOnInfo = table.LogOnInfo;
        var connectionInfo = logOnInfo.ConnectionInfo;
    
        // Set the Connection parameters.
        connectionInfo.DatabaseName = databaseName;
        connectionInfo.ServerName = serverName;
        connectionInfo.Password = password;
        connectionInfo.UserID = userName;
        table.ApplyLogOnInfo(logOnInfo);
    
        if (!table.TestConnectivity())
        {
            throw new ApplicationException(Resource.UnableToConnectCrystalReportToDatabase);
        }
    
        table.Location = Database + "." + "dbo" + "." + table.Location;
    }
    
    0 讨论(0)
  • 2020-12-18 08:58

    It only appears when your DataSet or DataTable is empty. So make sure it has data.

    0 讨论(0)
提交回复
热议问题