Skip to Content
0

Updating the database in a report working in the development environment but not an application

Dec 13, 2016 at 03:53 PM

29

avatar image
Former Member

Hi,

We have a number of crystal reports designed in CR XI which use an ODBC DSN for their data source and I need to change it as we've moved our servers to a different location, IP and we've also changed the user name and password.

I've updated the database server IP, user name and password details in the dsn and this works fine as I can connect to it using an application. Note that the name of the dsn remains the same it's just the IP, user name and password that have been changed.

I then opened the report in the CR development environment and went to the 'Set Datasource Location' screen and changed the user name and password and then did a verify database which worked fine. I then used the 'Show SQL Query' screen and filled in the report parameters which gave me a preview of the report. I then tried printing the report which again worked fine so I saved the report (not with the data in it).

When I run the report programatically in our old VB6 application it loads and you can add the parameters etc but when you call PrintOutEx at which point it gives the following error:

"Logon failed. Details: [Database Vendor Code: 18456 ]"

and wont print. Seems really strange as it works fine in the development environment. I've tried out sorts of things to get it to update the database but it's just not playing ball.

Incidentally I can change the database location programmatically using the function below called SetupAlternateDbConnection() which works great for reports that have only one parameter and sadly if you have reports with 2 or more parameters like us it will allow you to set the first parameter but the remaining parameters can't be found in the report parameter collection. If you ignore this and try to print the report it will fail and tell you it's missing parameters.

Any help anyone can give would be much appreciated.

Thanks

******************************************************************

Private Sub SetupAlternateDbConnection(

ByVal dbDSN As String,

ByVal dbDatabase As String,

Optional ByVal dbUserName As String = "",

Optional ByVal dbPassword As String = "")

' Setup the error handler. On Error GoTo ErrHandler

' Only do this if we have the dsn and database name.

If Trim(dbDSN) = "" Or Trim(dbDatabase) = "" Then Exit Sub

' Init.

Dim tbl As CRAXDDRT.DatabaseTable, tbls As CRAXDDRT.DatabaseTables

Dim crProperty As CRAXDDRT.ConnectionProperty

' Set the connection details of each table used in turn.

For Each tbl In crxCrystalReport.Database.Tables

' Setup the database server. Set crProperty = tbl.ConnectionProperties("DSN") crProperty.value = dbDSN

' Setup the user name.

Set crProperty = tbl.ConnectionProperties("User ID") crProperty.value = dbUserName

' Setup the password.

Set crProperty = tbl.ConnectionProperties("Password") crProperty.value = dbPassword

' Delete the current database setting if it's there.

On Error Resume Next

tbl.ConnectionProperties.Delete ("Database")

On Error GoTo ErrHandler

' Setup the database name.

tbl.ConnectionProperties.Add "Database", "EspStock"

Set crProperty = tbl.ConnectionProperties("Database") crProperty.value = "EspStock"

' Set the table location.

tbl.location = tbl.name

Next

ErrHandler:

' Setup the error handler.

If Err Then

' Report the error.

MsgBox "SetupAlternateDbConnection() - Error: " & Err.description

Err.Clear

End If

End Sub

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Best Answer
Don Williams
Dec 14, 2016 at 11:20 PM
0

CR Xi is old and no longer supported. If you are using it on a newer OS like 8.1 or 10 it's never been tested so unknown what is going to happen.

Time to upgrade to CR for VS.

Also, the RDC is no longer shipped or included in the redist packages and is for use in VS only.

If you want a report designer you need to use RAS and create your own.

Don

Share
10 |10000 characters needed characters left characters exceeded