Share via


Tutorial: Logging onto a Secure SQL Server Database

Introduction

When you use the CrystalReportViewer object model to log on to a secure SQL Server database, you must use classes from the CrystalDecisions.Shared namespace.

The properties of the ConnectionInfo class are used to connect to the database server or ODBC data sources. In this tutorial, you set the ServerName, DatabaseName, UserID and Password properties. If you choose only to set the DatabaseName, UserID, and Password properties, then you are logged on to the default server of the database that you have 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 retrieve the TableLogOnInfos instance from the LogOnInfo property of the CrystalReportViewer control. Then, you assign the ConnectionInfo instance to each TableLogOnInfo object in the TableLogOnInfos instance.

The logon code in this tutorial also works for subreports that are inserted into the main report. For the ReportDocument object model, you must modify the code to work for subreports, (see Tutorial: Logging onto a Secure SQL Server Database with a Subreport).

To build this tutorial using the ReportDocument object model, see Tutorial: Logging onto a Secure SQL Server Database. The ReportDocument object model is recommended over the CrystalReportViewer object model. For more information on which object model to use, see Which Object Model Should I Use?.

Sample Code

Each 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_CRVObjMod_DBLogon
  • C# Windows project: CS_Win_CRVObjMod_DBLogon
  • Visual Basic Web Site: VB_Web_CRVObjMod_DBLogon
  • Visual Basic Windows project: VB_Win_CRVObjMod_DBLogon

To locate the folders that contain these samples, see Tutorials' Sample Code Directory.

In this section: