Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Cannot connect ADO data source to reports
Message
General information
Forum:
Visual FoxPro
Category:
Crystal Reports
Miscellaneous
Thread ID:
00695306
Message ID:
00695463
Views:
12
This code will work:
LOCAL oCR AS CRAXDRT.Application
LOCAL oRpt AS CRAXDRT.Report
LOCAL oDB AS CRAXDRT.Database
LOCAL ocDBT AS CRAXDRT.DatabaseTables
LOCAL oDBT AS CRAXDRT.DatabaseTable

LOCAL oConn AS ADODB.Connection
LOCAL oRS AS ADODB.Recordset

* Handle the ADO stuff
oConn = CREATEOBJECT("ADODB.Connection")
oConn.ConnectionString = "Provider=VFPOLEDB.1;Data Source=C:\eFox\Data\tastrade.dbc;Password=''"
oConn.Open()
oRS = CREATEOBJECT("ADODB.RecordSet")
oRS.Open("Select * FROM Customer", oConn)

oCR = CREATEOBJECT("CrystalRuntime.Application")

oRpt = oCR.OpenReport("C:\EFox\ADO1.RPT")

* Create the Database object
oDB = oRpt.Database()

* Get a references to the DatabaseTables collection
ocDBT = oDB.Tables()

* Get a reference to the DatabaseTable object for table 1
oDBT = ocDBT.Item(1)

* Pass the Record Set to Crystal Reports
oDBT.SetDataSource(oRS)

IF oRPt.HasSavedData
	oRPT.DiscardSavedData()
ENDIF

oRpt.PrintOut()
>I've been working on Crystal for a while now, trying to integrate it into FoxPro. Its been so long I'm starting to get confused about what I know and don't know. So here's what I am trying to do including some samplecode. Please, if you see where I going wrong let me know.
>(PS - I've seen craig's site article and most of the articles already here so no need to forward me in that direction)
>
>My intent is to take a report that has already been designed by a user, and present it to all users. The users VIEWING the report should be able to refresh the data. I assume they are using DSNs when DESIGNING, but when VIEWING I want to provide a DSN-less data source. The data source is an MS SQL Server.
>
>So I've got a class that holds the following objects
>This.oConn = CREATEOBJECT("ADODB.Connection")
>This.oCRApp = CREATEOBJECT("CrystalRuntime.Application")
>This.oCRReport = CREATEOBJECT("CrystalRuntime.Report")
>Then the following is a global variable. I think I had it as part of the
>class, but for one reason or another changed it to a PUBLIC while testing.
>oRS_Borrower = CREATEOBJECT("ADODB.RecordSet")
>
>
>I open the connection with this code
>**** BEGIN CONNECTION CODE ADO ****
>LOCAL llWAIT_Active
>llWAIT_Active = .F.
>
>IF TYPE("This.oConn") <> "O" &&Object does not exist for ADO Connection
> This.oConn = CREATEOBJECT("ADODB.Connection")
>ENDIF
>
>WITH This.oConn
> .CommandTimeout = 60
> .ConnectionTimeout = 30
> .ConnectionString = This.ADODBConn_String()
>*Connection string returned by function is similar to the following
>*"Persist Security Info=False;driver={SQL Server};SERVER=Our-*Server;DATABASE=thedatabase;UID=user;PWD=pass"
> .CursorLocation = ADO_USECLIENT
> .Mode = ADO_MODEREADWRITE
> .Open(,,, 16)
>ENDWITH
>
>*Found out that the connection may take time to connect. I've seen everything
>* from no delay, to 1 second, to 5 seconds and longest at 15+ seconds.
>DO WHILE This.oConn.State = ADO_STATECONNECTING
> IF !llWAIT_Active
> WAIT WINDOW NOWAIT "Connecting to ADO Provider..."
> llWAIT_Active = .T.
> ENDIF
>ENDDO
>
>WAIT CLEAR
>**** END CONNECTION CODE ADO ****
>
>
>
>I then create a recordset and open it. I display some data in a WAIT window just to prove the connection is open and the recordset active
>**** BEGIN ADO RECORDSET CODE****
>PUBLIC oRS_Borrower
>
>LOCAL lcQuery
>*NOTE - This query is the query for the report
>lcQuery = "SELECT BORROWER.LOANNO, BORROWER.FIRST1, BORROWER.LAST1, BORROWER.SSN1, BORROWER.ADDR1, BORROWER.CITY1, BORROWER.STATE1, BORROWER.ZIP1, BORROWER.H_PHONE1, BORROWER.W_PHONE1 FROM db.dbo.BORROWER"
>
>
>oRS_Borrower = CREATEOBJECT("ADODB.RecordSet")
>WITH oRS_Borrower
> .ActiveConnection = This.oConn
> .Open(lcQuery)
>ENDWITH
>
>
>WAIT "Field = " + oRS_Borrower.Fields['LOANNO'].Value WINDOW
>**** END ADO RECORDSET CODE****
>
>
>
>Now here's the code I THINK is supposed to tell the report where to find the data for the report.
>**** BEGIN SETDATASOURCE CODE FOR REPORT ****
>LOCAL oTable, lnI
>oTable = NULL
>lnI = 0
>
>WITH This.oCRReport
> lnTableCount = .Database.Tables.Count
> FOR lnI = 1 TO lnTableCount
> oTable = .Database.Tables(lnI)
>
> oTable.SetLogOnInfo(qServer,qDefaultDatabase,"user","p")
> oTable.SetDataSource(oRS_Borrower)
> ENDFOR
>ENDWITH
>**** END SETDATASOURCE CODE FOR REPORT ****
>
>NOTE - I've tried all combinations of SETLOGONINFO and SETDATASOURCE, using them together and separately.
>
>When I run the report and refresh the data I get the following errors.
> TITLEBAR: Seagate Crystal Reports: Database Error
> MSGBOX : ODBC error:[Microsoft][ODBC Driver Manager]
> Connection not open
>and then
> TITLEBAR: Crystal Report Viewer
> MSGBOX : Server has not been opened.
>
>So that's it. At this point I'm completely confused and not even convinced that what I'm trying to do is possible. I know the ADO connection is good because we got a record source, so I assume somehow I'm not telling crystal the correct way to see the data.
>
>Thanks for the read... sorry about the length.
>
>Shawn Burke
Craig Berntson
MCSD, Microsoft .Net MVP, Grape City Community Influencer
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform