I have a SQL Server stored procedure with n number of varchar input parameters and returns 1 recordset. The Crystal Report connects to the database via ODBC. A separate ODBC is create for the Development database (pubs) and the Test database (pubsFred). My ASP code logs on to the table and sets the location and then assigns the parameter values to the report.
To replicate the environment, I created a PubsFred database which is a duplicate of the Pubs database with the modification of some data to determine that the setTableLocation worked correctly. Create a report based off of the following stored procedure:
Create Procedure dbo.TitleAuthors
(@au_lname varchar(25) = null)
As
Begin
Select Title, au_lname, au_fname
From Titles t
Inner join TitleAuthor ta On ta.title_id = t.title_id
Inner Join Authors a On a.au_id = ta.au_id
Where au_lname = @au_lname or @au_lname is null
Order By Title, au_Lname
End
GO
So normally when you change the table path it should be changed from Pubs.dbo.TitleAuthors to PubsFred.dbo.TitleAuthors. When you make the change don't forget to use the second ODBC DSN. Btw, the default database in the ODBC setup is Pubs for one and PubsFred for the other.
Here is a snippet of my ASP code (I have included only the code that I'm having difficulty with):
Dim DataSource
Dim DBName
Dim UserId
Dim Password
DataSource = "PubsODBC"
DBName = "Pubs"
UserId = "sa"
Password = "password"
'Create a reference to the tables collection of the main report
Set Tables = Session("oRpt").Database.Tables
For Each mnTable in Tables
With mnTable.ConnectionProperties
.Item("DSN") = DataSource
.Item("Database") = DBName
.Item("user ID") = UserId
.Item("Password") = Password
End With
' - 2 -
' SET THE LOCATION OF THE TABLE
' To set the location of the database file we set the location for each table
' using the DatabaseTable Object's Location property
'
sLocation = DBName & ".dbo." & Tables.item(1).Location
Response.Write "New Table Location: " & sLocation & "<br/>" & vbcrlf
mnTable.Location = sLocation
' mnTable.SetTableLocation sLocation, sLocation, ""
' mnTable.SetTableLocation sLocation, "", ""
Response.Write "Table Location: " & Tables.item(1).Location & "<br/>" & vbcrlf
Next
...
' - 2 -
' GET THE DATABASE'S STORED PROCEDURE PARAMETERS
' Create a variable and point it to the Stored Procedure Parameter
' in the report
set StoredProcParamCollection = Session("oRpt").ParameterFields
For Idx = 1 to StoredProcParamCollection.Count
' Create a variable and point it to the specific stored procedure
' that we want to work on
Set ThisParam = StoredProcParamCollection.item(cint(Idx))
' Save the new value for the Stored Procedure in the Store Procedure
FormField = "PROMPT" & CStr(Idx-1)
If Request.Form(FormField) <> "" then
ThisParam.AddCurrentValue(CStr( Request.form(FormField) ) )
Else
ThisParam.AddCurrentValue(CStr( "*" ))
End If
Next
Thank you in advance for taking the time in assisting with my problem.