Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing the report ODBC connection by ASP

Status
Not open for further replies.

Jarlaxle

Programmer
Feb 22, 2001
10
ES
My problem is the next:

I need to change the ODBC connection of my Crytal Reports by an ASP page (that is, a different ODBC and database name of the ones I set in the design of the report). For it I tried to use the "SetLogonInfo" and the "LogonServer" methods but neither worked. I tried all the syntaxis for both methods but I didn't have any results, specially the "SetLogonInfo", that I think that might be the method to use.

I will thank any advice or help about this.
 
Can you send your code so I can have a look at it? I've changed connections at runtime and I didn't have any problems...
 
1. Make sure your report was originaly created using ODBC (not native)connection.
2. Open your report in the Designer, go to Database...Set Location and get rid of database table ovner name for all of the tables(for example, it should read Customer insead of
mydb.Customer)
3. Make sure you don't have Save Data with Report option checked in the File menu.
4. The data source you switch to should has identical structure as your original one.
Those are steps I'd take first.
 

The code is the next:

Sub LanzarInforme(Informe,ClausulaWhere,ClausulaORDERBY, Nombre)
'Informe="../inf/edinfpub.rpt"
'ClausulaWhere = ""
'ClausulaORDERBY = ""
'ClausulaORDERBY = "EEFINCAS|{EEFINCAS.CEFINCA}|ASC,EEFINCAS|{EEFINCAS.CESUBFIN}|ASC"
InformeGen=Informe
InformeGen=Left(InformeGen,InStr(InformeGen,".rpt")-1)
Informe = Application("DirInf") & Informe

If Not IsObject (Session("oApp")) Then
Set Session("oApp") = Server.CreateObject("Crystal.CRPE.Application")
End If

If IsObject (Session("oRpt")) Then
Set Session("oRpt") = Nothing
End If

Set session("oRpt") = session("oApp").OpenReport(Informe, 1)

'--------------------------SUBREPORTS-----------------------------------

Set session("sections") = session("oRpt").Sections
Dim sectionCnt
sectionCnt = session("sections").Count

For i = 1 to sectionCnt
Set section = session("sections").Item(CInt(i))
Set sectionObjects = section.ReportObjects
Dim objectCnt
objectCnt = sectionObjects.Count

For j = 1 to objectCnt
If sectionObjects.Item(CInt(j)).Kind = 5 then
Set CRSubreports = session("oRpt").OpenSubreport(sectionObjects.Item(CInt(j)).Name)
For k = 1 to CRSubreports.Database.Tables.Count
set crtablesub = CRSubreports.Database.Tables.Item(CInt(k))
crtablesub.SetLogonInfo "srvjext","carga","sa",""
crtablesub.Location="carga.dbo."&crtablesub.Name
Next
End if
Next
Next
'-----------------------------------------------------------------------

'session("oRpt").MorePrintEngineErrorMessages = True
'session("oRpt").EnableParameterPrompting = True

Set Database = session("oRpt").Database
Set Tables = Database.Tables

'-----------------------------SORTBY------------------------------------
Temp = split (ClausulaORDERBY,",")

For i=0 to UBound (Temp)
Temp2 = split (Temp(i),"|")

Tabla = Temp2(0)
Campo = Temp2(1)

For j = 1 to Tables.Count
result = strcomp(Tables.Item(cint(j)).Name,cstr(Tabla))
If cint(result) = 0 Then
Set SortTable = Tables.Item(cint(j))
End if
Next

Set Fields = SortTable.Fields
For j = 1 to Fields.Count
result = strcomp(Fields.Item(cint(j)).Name,cstr(Campo))
If cint(result) = 0 Then
Set SortField = Fields.Item(cint(j))
End if
Next

Select Case Temp2(2)
case "DESC"
Orden = 1
case else
Orden = 0
End Select

session("oRpt").RecordSortFields.Add SortField,cInt(Orden)
Next
'-----------------------------------------------------------------------

session("oRpt").DiscardSavedData

for i=1 to Tables.Count
set crtable = Tables.Item(cint(i))
crtable.SetLogonInfo "serleg", "carga", "sa", ""
crtable.Location="carga.dbo."&crtable.Name
'Response.Write("carga.dbo."&crtable.Name)
next

session("oRpt").ReadRecords


On Error Resume Next

If Err.Number <> 0 Then
Response.Write &quot;An Error has occured on the server in attempting to access the data source&quot;
Else

If IsObject(session(&quot;oPageEngine&quot;)) Then
set session(&quot;oPageEngine&quot;) = nothing
set session(&quot;oPageEngine&quot;) = session(&quot;oRpt&quot;).PageEngine
End If

If ClausulaWhere <> &quot;&quot; then
session(&quot;oRpt&quot;).RecordSelectionFormula = cstr(ClausulaWhere)
End if

Set session(&quot;oPageEngine&quot;) = session(&quot;oRpt&quot;).PageEngine

hoy=Date()
fediaact=CStr(Day(hoy)) & &quot;-&quot; & CStr(Month(hoy)) & &quot;-&quot; & CStr(Year(hoy))

Session(&quot;oRpt&quot;).ExportOptions.DiskFileName = Application(&quot;DirInfGen&quot;)&InformeGen&&quot;_&quot;&Nombre&&quot;_&quot;&fediaact&&quot;.rpt&quot;
Session(&quot;oRpt&quot;).ExportOptions.FormatType = 1
Session(&quot;oRpt&quot;).ExportOptions.DestinationType = 1
Session(&quot;oRpt&quot;).Export False
End If
End Sub
 
What happens if you get rid of crtable.Location=&quot;carga.dbo.&quot; & crtable.Name
line in the loops?
 
hmmm..I'm not sure what happens if I quit that line in the loops...I think I did it once,but the problem remained.
I don't think that line affects much the procedure.
 
Does your report still show the old data or you're getting some error?
I'm doing exactly the same thing in my app, (except for
.Location part) and it works.
The only difference is I use &quot;call&quot; keyword to SetLogOnInfo:
Call crtable.SetLogonInfo &quot;serleg&quot;, &quot;carga&quot;, &quot;sa&quot;, &quot;&quot;

But it didn't work untill I got rid of db ovner name in front of a table name.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top