Error Occurred Reading Records: Server has not yet been opened.
ผมใช้ CR8.5 + ASP Classic , Database : MySQL ครับ
รบกวนช่วยดูและหาวิธีแก้ไขให้ด้วยครับ
โค้ดครับ
Code (ASP)
<%
'sConn_pdt = "DRIVER={MySQL ODBC 3.51 Driver}; SERVER=localhost; DATABASE=thainjr_employee; UID=root;PASSWORD=123456; OPTION=3"
Set oConn = Server.CreateObject("ADODB.Connection")
oConn.Open("DRIVER={MySQL ODBC 3.51 Driver}; SERVER=localhost; DATABASE=thainjr_employee; UID=root;PASSWORD=123456; OPTION=3")
' oConn.open "thainjr_employee","root" , "123456"
set session("oRs") = Server.CreateObject("ADODB.Recordset")
session("oRs").ActiveConnection = oConn
session("oRs").Open "select * from tbl_employee"
reportname = "test.rpt"
If Not IsObject (session("oApp")) Then
Set session("oApp") = Server.CreateObject("CrystalRuntime.Application")
End If
Path = Request.ServerVariables("PATH_TRANSLATED")
While (Right(Path, 1) <> "\" And Len(Path) <> 0)
iLen = Len(Path) - 1
Path = Left(Path, iLen)
Wend
If IsObject(session("oRpt")) then
Set session("oRpt") = nothing
End if
On error resume next
Set session("oRpt") = session("oApp").OpenReport(path & reportname, 1)
If Err.Number <> 0 Then
Response.Write "Error Occurred creating Report Object: " & Err.Description
Set Session("oRpt") = nothing
Set Session("oApp") = nothing
Session.Abandon
Response.End
End If
session("oRpt").MorePrintEngineErrorMessages = False
session("oRpt").EnableParameterPrompting = False
'selection_formula="{R_holder.holdername}='" & request("h") &"'"
session("oRpt").DiscardSavedData
'session("oRpt").RecordSelectionFormula = cstr(selection_formula)
set Database = session("oRpt").Database
'Instantiates a database collection which references the database(s) used in the report.
set Tables = Database.Tables
'Instantiates a Tables collection which references the Tables of the Database object.
set Table1 = Tables.Item(1)
Table1.SetPrivateData 3, session("oRs")
On Error Resume Next
session("oRpt").ReadRecords
If Err.Number <> 0 Then
Response.Write "Error Occurred Reading Records: " & Err.Description
Set Session("oRpt") = nothing
Set Session("oApp") = nothing
Session.Abandon
Response.End
Else
If IsObject(session("oPageEngine")) Then
set session("oPageEngine") = nothing
End If
set session("oPageEngine") = session("oRpt").PageEngine
End If
%>
<BODY BGCOLOR=C6C6C6 ONUNLOAD="CallDestroy();" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<object id="CRViewer"
classid="CLSID:C4847596-972C-11D0-9567-00A0C9273C2A"
width=100% height=100%
CODEBASE="/viewer/activeXViewer/activexviewer.cab#Version=8,0,0,224">
<param name="EnableRefreshButton" value=0>
<param name="EnableGroupTree" value=0>
<param name="DisplayGroupTree" value=0>
<param name="EnablePrintButton" value=1>
<param name="EnableExportButton" value=1>
<param name="EnableDrillDown" value=1>
<param name="EnableSearchControl" value=1>
<param name="EnableAnimationControl" value=0>
<param name="EnableZoomControl" value=1>
</object>
<script language="VBScript">
<!--
Sub Window_Onload
On Error Resume Next
Dim webBroker
Set webBroker = CreateObject("WebReportBroker.WebReportBroker")
if ScriptEngineMajorVersion < 2 then
window.alert "IE 3.02 users on NT4 need to get the latest version of VBScript or install IE 4.01 SP1. IE 3.02 users on Win95 need DCOM95 and latest version of VBScript, or install IE 4.01 SP1. These files are available at Microsoft's web site."
CRViewer.ReportName = Location.Protocol + "//" + Location.Host + "/scrsamples/Web Component Server/rptserver.asp"
else
Dim webSource
Set webSource = CreateObject("WebReportSource.WebReportSource")
webSource.ReportSource = webBroker
webSource.URL = Location.Protocol + "//" + Location.Host + "/scrsamples/rptserver.asp"
webSource.PromptOnRefresh = True
CRViewer.ReportSource = webSource
end if
CRViewer.ViewReport
End Sub
-->
</script>
<script language="javascript">
function CallDestroy()
{
window.open("Cleanup.asp");
}
</script>
<script language="javascript">
window.moveTo(0,0);
//window.resizeTo(screen.availwidth,screen.availheight);
</script>