1216241 - Changing from NT Authentication to SQL Authentication in .NET at Runtime

SAP Knowledge Base Article - Public

1216241 - Changing from NT Authentication to SQL Authentication in .NET at Runtime

Symptom

A Crystal report (CR) is created using NT Authentication (integrated security). Attempting to switch from NT Authentication to SQL Authentication at runtime has no effect when using Crystal Reports for Visual Studio .NET 2002.

Why does the report still use NT Authentication after switching to SQL Authentication?

Resolution

This behavior occurs because Crystal Reports for

Visual Studio .NET 2002 does not support changing from

NT Authentication (integrated security) to SQL

Authentication at runtime.

This is a known issue with Crystal Reports for Visual

Studio .NET 2002 and has been tracked. The Track ID

is ADAPT00183258.

To work around this issue, upgrade to either

Crystal Reports 9 Developer Edition or Crystal Reports

9 Advanced Edition as both editions support this

functionality.

====================

NOTE:

While it is possible to change from NT Authentication

to SQL Authentication at runtime, it is not possible to

change from SQL Authentication to NT Authentication at

runtime with either version.

====================

The follow sample code (in both VB .NET and C# .NET)

demonstrates changing from NT Authentication to SQL

Authentication. This code assumes that the report has

been designed using NT Authentication.

VB .NET

--------

Imports CrystalDecisions.CrystalReports.Engine

Imports CrystalDecisions.Shared

Dim crReportDocument As CrystalReport1

Dim crDatabase As Database

Dim crTables As Tables

Dim crTable As Table

Dim crtableLogOnInfo As TableLogOnInfo

Dim crConnectionInfo As ConnectionInfo

Private Sub ChangeToSQLAuthentication()

' Create a new report

crReportDocument = New CrystalReport1()

crConnectionInfo = New ConnectionInfo()

' Set the connection information

crConnectionInfo.ServerName = "myServer"

crConnectionInfo.DatabaseName = "Pubs"

crConnectionInfo.UserID = "myUserID"

crConnectionInfo.Password = "myPassword"

' Obtain a reference to the tables

crDatabase = crReportDocument.Database

crTables = crDatabase.Tables

' Loop through all the tables and set the

' logon information

For Each crTable In crTables

crtableLogOnInfo = crTable.LogOnInfo

crtableLogOnInfo.ConnectionInfo =

crConnectionInfo

crTable.ApplyLogOnInfo(crtableLogOnInfo)

' This line is only necessary if you are

' changing the database location

' It removes the database and owner from

' the location property and sets the location

' equal to just the table name

crTable.Location =

crTable.Location.Substring(crTable.Location.LastIndexOf(

".") + 1)

Next crTable

End Sub

C# .NET

--------

using CrystalDecisions.CrystalReports.Engine;

using CrystalDecisions.Shared;

CrystalReport1 crReportDocument;

Database crDatabase;

CrystalDecisions.CrystalReports.Engine.Tables crTables;

TableLogOnInfo crTableLogOnInfo;

ConnectionInfo crConnectionInfo;

private void changeToSqlAuthentication()

{

// Create new report

crReportDocument = new CrystalReport1();

crConnectionInfo = new ConnectionInfo();

// Set Connection Information

crConnectionInfo.ServerName="tsdotnet1";

crConnectionInfo.DatabaseName="Pubs";

crConnectionInfo.UserID="sa";

crConnectionInfo.Password="admin";

// Obtain a reference to the tables

crDatabase = crReportDocument.Database;

crTables = crDatabase.Tables;

// Loop through all the tables and set the logon

// information

foreach (CrystalDecisions.CrystalReports.Engine.Table

crTable in crTables)

{

crTableLogOnInfo = crTable.LogOnInfo;

crTableLogOnInfo.ConnectionInfo = crConnectionInfo;

crTable.ApplyLogOnInfo(crTableLogOnInfo);

// This line is only necessary if you are changing

// the database location it removes the database

// and owner from the location property and

// sets the location equal to just the table name

crTable.Location =

crTable.Location.Substring(crTable.Location.LastIndexOf(

".")+1);

}

}

Keywords

DOTNET VS.NET TRUSTED CONNECTION VB.NET C# SECURITY PERMISSIONS Crystal Reports for Visual Studio Database Login NT Authentication and SQL Authentication , c2013558 , KBA , BI-DEV-NET-SDK , .NET SDK / COM SDK , How To

Product

SAP Crystal Reports XI ; SAP Crystal Reports XI R2