
Originally Posted by
Thierry69
Is it possible for you to post the ASP code of your "https://vbRichClient.com/asp/ADODBTest.asp"?
Sure, here it is (please google for json2.asp, which was not written by me)...
Code:
<% @EnableSessionState=False %>
<!--#include file="json2.asp"-->
<%
'Helper-Functions which are normally located in another include-file (similar to the json2.asp at the top)
Function GetStringFromUTF8Bytes(B)
With CreateObject("ADODB.Stream")
.Type = 1
.Open
.Write B
.Position = 0
.Type = 2
.Charset = "utf-8"
GetStringFromUTF8Bytes = .ReadText
End With
End Function
Function OpenConn(ServerFileName)
Set OpenConn = CreateObject("ADODB.Connection")
OpenConn.CursorLocation = 3 ' adUseClient
OpenConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & ServerFileName
End Function
Function GetRs(Query, Cnn)
Set GetRs = CreateObject("ADODB.Recordset")
GetRs.Open Query, Cnn, 3, 4 'adOpenStatic, adLockBatchOptimistic
End Function
Function GetByteContentFromRs(Rs)
If Not IsObject(Rs) Then
Set Rs = CreateObject("ADODB.Recordset")
Rs.Fields.Append "Empty", 8
Rs.Open
Rs.AddNew
End If
Dim Stream
Set Stream = CreateObject("ADODB.Stream")
Rs.Save Stream, 0 '<- 0 = adPersistADTG
GetByteContentFromRs = Stream.Read(Stream.Size)
End Function
'and here the lines needed to serve the request (making use of the Helper-Functions)
On Error Resume Next
Dim Params: Set Params = JSON.parse(GetStringFromUTF8Bytes(Request.BinaryRead(Request.TotalBytes)))
Dim Cnn: Set Cnn = OpenConn(Server.MapPath(Params.DBName))
Dim Rs: Set Rs = GetRs(Params.SQL, Cnn)
If Err Then
Response.Write "{""Err"": """ & Err.Description & """}"
Else
Response.BinaryWrite GetByteContentFromRs(Rs)
If Err Then Response.Write "{""Err"": """ & Err.Description & """}"
End If
Cnn.Close
%>
Olaf