Logging on to Secure Data Sources
Using secure data sources with your report can be an initial source of confusion. There are a lot of types of data sources and just as many ways to connect to them. This is a lot of information comprehend.
Crystal Reports is designed so that the user Id you entered at design time is saved with the report file, but not the password. This is done so that the security of your database isn’t compromised. If you are printing from a non-secure data source then the report prints fine. If the data source is secure then you are prompted with a dialog box to enter the login credentials. You can prevent the dialog box from appearing by setting the user credentials during runtime. This lets you manage security in a way that conforms to your corporation’s policies.
This section only applies to reports that use the Pull Model. The Pull Model saves connection information with the report and you have to modify the connection properties to set the user credentials. This doesn’t apply if you are using the Push Model because you had to connect to the data source manually. The report doesn’t save any of the connection information and consequently there is nothing for you to change.
Logging on to a secure data source uses two classes: Table and ConnectionInfo. The Table class is the primary class. The report object stores each table that it uses within a Tables collection. Loop through the Tables collection to reference each Table object. The Name property identifies which database table it is. If you want to apply different login credentials for each table, then examine the Name property to identify each table.
Within the Table object is the LogOnInfo object. This is only used to get a reference to the ConnectionInfo object. The ConnectionInfo object has the properties UserId and Password. The UserId property is already set to the user Id that you entered during design mode. If this is what you want, then you do not have to change it. However, you probably want to reassign it with the current user’s credentials. The Password property is always empty. You have to assign it with the current user’s password.
When the UserId and Password properties are set, call the ApplyLogOnInfo() method of the Table object. After this is done for each table, the report is ready print. Crystal Reports attempts to log on to the data source when it prints. If the information is valid, then the user is logged in and the report prints. If the information isn’t valid, then a login dialog box is displayed so that new user information can be entered.
Setting the logon properties is done differently depending upon whether you are doing so with the ReportDocument object or if you are using the viewer control. Although both use the same objects and properties, the way you get to this information is different. This is explained in detail in the next two sections.