Tutorial: Logging onto a Secure SQL Server Database Using Integrated Security
Introduction
To log onto a secure SQL Server database, you use classes from the ReportDocument object model.
The ReportDocument object has a Database property that returns a Database instance. This Database instance contains the database information for the report, including a Tables property that returns a Tables indexed class instance. Individual Table instances can then be retrieved from the Tables indexed class.
Logon occurs at the granular level of each Table instance, which must be granted individual access to the secure SQL Server. This is done by placing logon information into a ConnectionInfo instance, and then, within a for loop, applying that ConnectionInfo instance to the ConnectionInfo Property of each Table instance.
The properties of the ConnectionInfo class include the following:
- ServerName
- DatabaseName
- UserID (not used in this tutorial)
- Password (not used in this tutorial)
- IntegratedSecurity
Note
If you wish to work through a tutorial that uses SQL Authentication (and therefore uses the UserID and Password properties rather than the Integrated Security property), see Tutorial: Logging onto a Secure SQL Server Database Using SQL Authentication.
If you choose only to set the DatabaseName, and IntegratedSecurity properties, you will be logged onto the default server and database specified within the report. However, if you choose to assign an alternate ServerName property, you can redirect the report to a different server at runtime.
You begin by creating a report containing data from a secure SQL server database.
You can complete this tutorial by using classes of the CrystalReportViewer object model; however, the ReportDocument object model is recommended. For more information on which object to use, see Which Object Model Should I Use?.
Sample Code
This tutorial comes with Visual Basic and C# sample code that show the completed version of the project. Follow the instructions in this tutorial to create a new project or open the sample code project to work from a completed version.
The sample code is stored in folders that are categorized by language and project type. The folder names for each sample code version are as follows:
- C# Web Site: CS_Web_RDObjMod_DBLogonIntegratedSecurity
- C# Windows project: CS_Win_RDObjMod_DBLogonIntegratedSecurity
- Visual Basic Web Site: VB_Web_RDObjMod_DBLogonIntegratedSecurity
- Visual Basic Windows project: VB_Win_RDObjMod_DBLogonIntegratedSecurity
To locate the folders that contain these samples, see Tutorials' Sample Code Directory.