I use http and asp page to run stored procedures and return data. Here is sample:1) What would be the best way to gather the MS Sql data? I have complete control over the server so can pre-filter the data or can do it while connected.
qry=request.form'("qry")
sqlConnectStr=session("ConnectionString")
Set SqlConn = Server.CreateObject("ADODB.Connection")
sqlConn.open session("ConnectionString")
set oRs=server.CreateObject("ADODB.RecordSet")
ors.Open qry,sqlConn,3,1
on error resume next
if oRs.BOF and oRs.EOF then
Response.Write("0")
else
Response.Write(oRs.GetString(2)) 'this returns chr(13) separated records and a TAB separated record
end if
Sub GetRecords(result As String) As List
Dim aList As List
aList.Initialize
'Dim line As String
If EndRecord="" Then
EndRecord=Chr(13)'Chr(0)
End If
If result="0" Then 'nothing
Else
Dim lines() As String
lines=Regex.Split(EndRecord,result)
Dim A As Int
For A=1 To lines.Length
aList.Add(lines(A-1))
Next
End If
Return aList
End Sub
If job.Success Then
Dim Records As List
Records=GetRecords(job.GetString)
For Each ALine As String In Records
Dim line() As String
line=Regex.Split(TAB,ALine)
Edit1.text=line(0)
Edit2.text=line(1)
...etc
I Use SQL Lite to log everything. My transactions are done in real-time unless there is a network glitch. I have a "posted" flag such that I can return any "SQL Script" that hasn't been posted yet.2) What is the best storage method on the tablet? SQLITE?
Sub LogSQL(SQL As String) As Int
Dim sSql As String
sSql="INSERT INTO SQLLog(Date,SQL,Posted) VALUES(" & Delphi.Date & ",'" & SQL.Replace("'","""") & "',0)" 'the date is only for the "log" to know when it was logged
Log(sSql)
ASQL.ExecNonQuery(sSql)
sSql="Select last_insert_rowid()"
Return ASQL.ExecQuerySingleResult(sSql)
Dim sSQL As String
sSQL="UPDATE SQLLog SET POSTED=1 WHERE ID=" & ID
ASQL.ExecNonQuery(sSQL)
As I said earlier, I use http and Stored Procedures to post data to my server. I do thousands of transactions per day in real-time. You could store your "SQL INSERT Script" in a simple SQLLITE table with the "posted" flag=0. When ready to "post" your transactions you loop through your table that has posted=0 and post to http. I successful you flag it posted=13) How would I best return the data to the server? I will want to flag transactions as sent so they remain on the tablet but are not sent each time. (That should be easy).
I would just do it within the app. Maybe run it as a service.4) Should the data transfer functions be in their own app separate from the data entry app?
Qsrtechs reply was very helpful and very complete. However, after reading some threads I found this one about remote database connector.
http://www.b4x.com/android/forum/threads/remote-database-connector-connect-to-any-remote-db.31540/
I was able to configure the server in no time and with a few tweaks I was accessing SQL data directly in the application. I am very pleased with the performance and believe this is going to be the direction I go. Check out the tutorial and be sure to check out the link to the other required files.
Hi Qsrtech,
I also have the same requirement described. But I can not understand how should I implement the connection to the database and how to read and write data to the sql database.
if you can, would you do me the courtesy to send me a small example of how you did.
thank you very much in advance.
roberto
Notepad lol. Is your server set up to run asp? IIS isn't running asp by default anymore. Anyways you can use asp.net, i just haven't bothered trying to switch over. For what I'm doing asp is good enough.qsrtech,
What are you using to create the asp page? I have created many aspx pages in visual studio but never an asp page standing alone.
Dim http As HttpJob
http.Initialize("SQL",Me)
Dim SQL as String
SQL="EXECUTE YOUR STORED PROCEDURE OR SQL SCRIPT"
SQL=SQL.Replace(" ","%20")'I like to remove spaces just in case
http.PostString(SQLServer,SQL) 'SQLServer is a variable to the webserver, i.e. http://www.yourserver.com/getsql.asp
http.GetRequest.SetHeader("Authorization",SOMECODE) 'you can use a header like this but you have to update the asp script to grab the header and do what you want with it
Sub JobDone(job As HttpJob)
If job.success Then
Dim result As String=job.getstring
If result<>"0" then
Dim rows() As String=Regex.Split(Chr(13),result)
Select Case job.jobname
Case "AJOBNAME"
For Each record As String In rows
Dim cols() As String=Regex.Split(TAB,record)
x=cols(0)
y=cols(1)
z=cols(2)
'etc....
Next
End Select
Else
'nothing returned, do something?
End If
End If
End Sub
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?