For Programmers: Free Programming Magazines  


Home > Archive > Visual Basic Crystal Reports > January 2006 > HELP! Can't change crystal report database source dynamically!









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author HELP! Can't change crystal report database source dynamically!
Dav

2006-01-23, 7:07 pm

Hi,

I am trying to change a crystal report database source dynamically via
code without any luck:

'''''''''''''''''''''''''''''
For Each tbl In rpt.Database.Tables

tbl.SetLogOnInfo(strServer, strDatabase, strUser,
strPassword)

Next

rpt.EnableParameterPrompting = False
rpt.DiscardSavedData()

rpt.Database.LogOnServer("pdssql.dll", strServer,
strDatabase, strUser, strPassword)

'I tried each of the following and nothing works:
'rpt.Database.LogOnServer("pdssql", strServer, strDatabase, strUser,
strPassword)
'rpt.Database.LogOnServer("PDSSQL.DLL", strServer, strDatabase,
strUser, strPassword)
'rpt.Database.LogOnServer("PDSSQL", strServer, strDatabase, strUser,
strPassword)

''''''''''''''''''''''''
I don't even get an error when the code runs!

The only way I can change the data source is going into the report
itself and right clicking onto it and changing the location.

So, how can I change a report data source via code in VB?

Please post complete solutions or links.
I appreciate your help!

Dav

andy

2006-01-24, 7:58 am

The connection you initially set the report up with must use windows
security if you're to use that or sql if you're using a specific user.
It doesn't seem to work if you try switching dynamically.
Or at least I couldn't get it to.
This uses windows security.
Stick a user and password in if that's not what you want.


Dim MyTableLogOnInfo As New TableLogOnInfo
Dim MyDBConnectionInfo As New ConnectionInfo

'-----------
Dim log As TableLogOnInfo
Dim tbl As Table

crConnectionInfo = New ConnectionInfo
With crConnectionInfo
.ServerName = "Server"
.DatabaseName = "Database"
.UserID = String.Empty
.Password = String.Empty
End With
For Each tbl In myreport.Database.Tables
log = tbl.LogOnInfo
log.ConnectionInfo = crConnectionInfo
tbl.ApplyLogOnInfo(log)
tbl.Location =
tbl.Location.Substring(tbl.Location.LastIndexOf(".") + 1)
Next

Shariq

2006-01-24, 7:07 pm

Use the following code; it should work.

Dim crtableLogoninfos As New TableLogOnInfos
Dim crtableLogoninfo As New TableLogOnInfo
Dim crConnectionInfo As New ConnectionInfo
Dim CrTables As Tables
Dim CrTable As Table
Dim TableCounter

With crConnectionInfo
.ServerName = gsODBCName
.DatabaseName = gsDatabase
.UserID = gsUserID
.Password = gsPassword
End With
CrTables = sReportName.Database.Tables
Try
For Each CrTable In CrTables
crtableLogoninfo = CrTable.LogOnInfo
crtableLogoninfo.ConnectionInfo = crConnectionInfo
CrTable.ApplyLogOnInfo(crtableLogoninfo)
Next
Catch ex As Exception
MsgBox(Err.Description, MsgBoxStyle.Critical, "MoQ")
End Try


"andy" wrote:

> The connection you initially set the report up with must use windows
> security if you're to use that or sql if you're using a specific user.
> It doesn't seem to work if you try switching dynamically.
> Or at least I couldn't get it to.
> This uses windows security.
> Stick a user and password in if that's not what you want.
>
>
> Dim MyTableLogOnInfo As New TableLogOnInfo
> Dim MyDBConnectionInfo As New ConnectionInfo
>
> '-----------
> Dim log As TableLogOnInfo
> Dim tbl As Table
>
> crConnectionInfo = New ConnectionInfo
> With crConnectionInfo
> .ServerName = "Server"
> .DatabaseName = "Database"
> .UserID = String.Empty
> .Password = String.Empty
> End With
> For Each tbl In myreport.Database.Tables
> log = tbl.LogOnInfo
> log.ConnectionInfo = crConnectionInfo
> tbl.ApplyLogOnInfo(log)
> tbl.Location =
> tbl.Location.Substring(tbl.Location.LastIndexOf(".") + 1)
> Next
>
>

Dav

2006-01-25, 7:19 pm

Thanks guys for the code. I got the code to execute but now when I try
to export to an excel file, I get the following error messge when I run
rpt.Export():

"missing parameter field current value"

I don't have any parameter's to pass as I am passing in a query (via
rpt.SetDataSource(strReportQuery)).

I use to use rpt.EnableParameterPrompting = False but
EnableParameterPrompting is not a property anymore on this type of
report object. This is how I am trying to exporting the report to
excel:

'''''''''''''''''''''
rpt.ExportOptions.ExportDestinationType =
ExportDestinationType.DiskFile
rpt.ExportOptions.ExportFormatType = ExportFormatType.Excel


Dim objOptions As DiskFileDestinationOptions = New
DiskFileDestinationOptions
objOptions.DiskFileName = strFullExportFileName
rpt.ExportOptions.DestinationOptions = objOptions
rpt.Export()

''''''''''''''''

So, how do you export using the report object in your code without
getting the "missing parameter field current value" error?

Thanks,

Dav

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com