Share via


Tutorial: Logging onto a Secure SQL Server Database Using SQL Authentication

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
  • Password
  • IntegratedSecurity (not used in this tutorial)

Note

If you wish to work through a tutorial that uses Windows authentication (and therefore uses the IntegratedSecurity property rather than the UserID and Password properties), see Tutorial: Logging onto a Secure SQL Server Database Using Integrated Security.

If you choose only to set the DatabaseName, UserID, and Password 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?.

To build this tutorial using the CrystalReportViewer object model, see Tutorial: Logging onto a Secure SQL Server Database in the CrystalReportViewer tutorials.

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_DBLogon
  • C# Windows project: CS_Win_RDObjMod_DBLogon
  • Visual Basic Web Site: VB_Web_RDObjMod_DBLogon
  • Visual Basic Windows project: VB_Win_RDObjMod_DBLogon

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

In this section: