Print Page | Close Window

Crystal set location

Printed From: Crystal Reports Book
Category: Crystal Reports for Visual Studio 2005 and Newer
Forum Name: Writing Code
Forum Discription: .NET programming API, report integration
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=4600
Printed Date: 29 Apr 2024 at 3:54am


Topic: Crystal set location
Posted By: donsls
Subject: Crystal set location
Date Posted: 22 Oct 2008 at 12:02pm
I have the following code to load a report and set its location (VS 2005). I am passing a report that has a table and an SQL command.

Protected Sub SetDBLogonForReport(ByVal sDbServer As String, _

ByVal sDbName As String, _

ByVal sDbUserName As String, _

ByVal sDbPassword As String, _

ByVal reportName As ReportDocument)

Dim crDatabase As Database

Dim crTables As Tables

Dim crTable As Table

Dim crLogOnInfo As TableLogOnInfo

Dim crConnInfo As New ConnectionInfo

crDatabase = reportName.Database

crTables = crDatabase.Tables

crTables.Reset()

Try

For Each crTable In crTables

With crConnInfo

.ServerName = sDbServer

.DatabaseName = sDbName

.UserID = sDbUserName

.Password = sDbPassword

.IntegratedSecurity = True

End With

crLogOnInfo = crTable.LogOnInfo

crLogOnInfo.ConnectionInfo = crConnInfo

crTable.ApplyLogOnInfo(crLogOnInfo)

crTable.Location = crTable.Location

Next

Catch ex As Exception

Response.Write(ex.Message)

End Try

End Sub

When I pass the report to this function my report runs and I can see the data, but because of the
crTable.Location = crTable.Location
 
It gives me the following error on top of the page.
Logon failed. Details: IM002:[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified Error in File C:\Temp\crystalreport2 {D3AAE90E-582A-4FF2-8FF5-E98454F7AA67}.rpt: Unable to connect: incorrect log on parameters.
 
The moment I comment this, it works without any issues, but when I deploy it and run it from there, I get the following error.
 
Invalid Argument provided. Failed to open a rowset. Error in File C:\Temp\CrystalReport1 {3BEDABA1-0669-43F6-92F1-F9788E07EB97}.rpt: Invalid argument for database
 
If my report has only tables, I don't get the second error, but still it gives me the first error with the setlocation statement.
I even tried the following statements.

'crTable.Location = sDbName & "." & "dbo" & "." & crTable.Location.Substring(crTable.Location.LastIndexOf(".") + 1)

'crTable.Location = crTable.Location.Substring(crTable.Location.LastIndexOf(".") + 1)

 
Still no luck. Can any one help? Any help is greatly appreciated.
 
 
 
 



Print Page | Close Window