Android Tutorial Connect Android to MS SQL Server Tutorial

Status
Not open for further replies.

Juzer Hussain

Active Member
Licensed User
Longtime User
Hi Erel,

I m trying to read a datatable (2000 records, 22 columns, max size 200 varchar) thru GetString().It takes sometime in downloading and When I loop thru records it stops at a line saying ArrayOutOfBounds. I suspect there is some limit to it. Is there any other better method of doing this.

Pls guide me.

Thanks
Juzer
 

Juzer Hussain

Active Member
Licensed User
Longtime User
Hi Erel,

Continuing with above......
I m using Download2 function and in Sub JobDone GetString is returning value in response(string) variable
The line where error is coming is
If m.Get("FType")="CS" Then
gClassSection(k)=m.Get("SubCategory")
k=k+1
End If
Error msg is
java.lang.ArrayIndexOutOfBoundsException: length=0; index=0

Pls guide me.

Thanks
Juzer
 

Juzer Hussain

Active Member
Licensed User
Longtime User
RESOLVED

Sorry array declaration was the problem in gClassSection() (it should be gClassSection(n)) where n is some number

Juzer
 

Eduardo Bardales

Member
Licensed User
Longtime User
Hi I´ve got this Web service, run Ok


**************************************************
This is the code in VB2010 for connect to sql server database
********************************************
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.ComponentModel
Imports Microsoft.SqlServer
Imports System.Data
Imports System.Data.SqlClient

<System.Web.Services.WebService(Namespace:="http://192.168.1.39:2272/")> _
<System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<ToolboxItem(False)> _
Public Class SqlService
Inherits System.Web.Services.WebService

<WebMethod()> _
Public Sub InsertaRegistro(ByVal CadenaInsercion As String) ' As String
Try
Dim CadConeccion As String = "Server=VICTOR\SQLEXPRESS;Database=pruebawebservice;user Id=sa; Password=Siesac2016;"
Dim Con As SqlConnection = New SqlConnection(CadConeccion)
Dim Comm As SqlCommand = New SqlCommand(CadenaInsercion, Con)
Con.Open()
Comm.ExecuteNonQuery()
Con.Close()
Catch err As Exception
End Try
End Sub
End Class
*********************************************
I need to send data from B4A textedits to the webservice.
How can I do it ?
I have this code in b4a
**********************************************
Dim ServerUrl as string
ServerUrl = "http://192.168.1.39:2272/SqlService.asmx?op=InsertaRegistro"
job1.PostString(ServerUrl, "INSERT INTO tRegistro (Equipo, FechaHora) VALUES('" & txtEquipo & "'" & ",'" & txtFechaHora & "'"))
**********************************************
But appear this message
Error: org.apache.http.conn.ConnectTimeoutException: Connect to /192.168.1.39:2272 timed out

**********************************************
Helpme please!!
 

Sytek

Active Member
Licensed User
Longtime User
Hello, in this tutorial or example anyone can acces the server right?; Knowing the correct link I mean. or how can I encrypt and decrypt the link?

Thank's in advance
 

Sytek

Active Member
Licensed User
Longtime User
Yes.

You can obfuscate the link string (see the obfuscation tutorial).

Switch to RDC for a better solution.

Hello Erel
Thank's for the reply.
I Know about RDC; But I'm testing this one.

See... this is a First post Example link.
http://www.example.com/test1.aspx?query=select * from table_1
Now it returns a json string and anybody can read the retrieved query (via web browser)
What I need is to encrypt the link like this
http://www.example.com/test1.aspx?query=abcdef=rfttdrertt (not base64 'cause that's too easy to decode)
...and in the site part decrypt the query string,

Thank's in advance.
 

Helmut S

Member
Licensed User
Longtime User
Hello everyone,

I tried to run the Android example but could not even compile it. Just got the compiler message:

B4A version: 5.50
Parsing code. (0.01s)
Compiling code. (0.03s)
Compiling layouts code. (0.00s)
Generating R file. (0.35s)
Compiling debugger engine code. (0.93s)
Compiling generated Java code. Error
B4A line: 24
If init = False Then Process_Globals
javac 1.7.0_76
src\anywheresoftware\b4a\samples\sqlserver\httputilsservice.java:325: error: cannot find symbol
_process_globals();};
^
symbol: method _process_globals()
location: class httputilsservice
Can anybody help me to solve the problem? Thanks in advance,

Helmut
 

BarryW

Active Member
Licensed User
Longtime User

How to run the ASP Code to be access by android...
 

SCIS

Active Member
Licensed User
Longtime User
What do i need to chance in the ASP.NET code to let it work for my mssql server and b4a project?
and where do i need to place this file so b4a could find it?
 

SCIS

Active Member
Licensed User
Longtime User
You need to change the username and password.

This script should be hosted in a IIS server.

So i don't need to chance the datasource or query? I just need to fill the username and password of my database in the code.

The server is hosted at school, do i need to send my aspx file to my mentor and ask him to put this script on the IIS server?

Thanks
 

mkvidyashankar

Active Member
Licensed User
Longtime User
I am using the same code with asp.net web page.
I am getting results from web page
but not getting in the phone. here is the code

B4X:
Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Dim ServerUrl As String
    ServerUrl = "http://89.238.162.147/gpm/query.aspx"
    Private kvs As KeyValueStore
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

    Private Panel1 As Panel
    Private ListView1 As ListView
    Dim id As Int
    Dim dept As String
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
Activity.LoadLayout("Layout1")
    If FirstTime Then
        HttpUtils.CallbackActivity = "get_data"
        HttpUtils.CallbackJobDoneSub = "JobDone"
            kvs.Initialize(File.DirDefaultExternal, "datastore")
    End If
      
            id = kvs.GetSimple("Employeeid")
            dept=Main.department
'            user=    kvs.GetSimple("username") ' FirstName,MiddleName,LastName
'            department =kvs.GetSimple("department") 'IcDepartment  
'            designation=kvs.GetSimple("designation")
'            address=kvs.GetSimple("Address") ' Address1,Address2,Address3
'            email=kvs.GetSimple("email") 'Email
'            phone=kvs.GetSimple("phone") 'PhoneNo
        Dim sqltxt As String
        If dept="Department: Quality" Then  sqltxt  ="SELECT * FROM [GRAMAPATHA].[dbo].[TrInspectionSheduleHeader] WHERE  IcMonitor =" & id & " order by [DateOfVisit]  desc"
        HttpUtils.PostString("Job1", ServerUrl, sqltxt)
      
    'HttpUtils.PostString("Job1", ServerUrl, "SELECT * FROM [GRAMAPATHA].[dbo].[TrInspectionSheduleHeader] WHERE IcDivision=3 order by [DateOfVisit]  desc")
    Panel1.SetLayout(0,0,100%x,100%y)
    ListView1.SetLayout(0,30dip,100%x,100%y-30dip)
End Sub


Sub Activity_Resume
If HttpUtils.Complete = True Then JobDone(HttpUtils.Job)
End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub
Sub JobDone (Job As String)
    If HttpUtils.IsSuccess(ServerUrl) Then
        Dim parser As JSONParser
        Dim response As String
        response = HttpUtils.GetString(ServerUrl)
        parser.Initialize(response)
        Dim rows As List
        rows = parser.NextArray
      
        'work with result
        'rows is a List. Each item is a Map with the columns names as keys and the db values as the values.
        For i = 0 To rows.Size - 1
            Log("Rows #" & i)
            Dim m As Map
            m = rows.Get(i)
            ListView1.AddTwoLines(m.Get("MonitorId"),m.Get("DivisionId"))
            Log("col1=" & m.Get("MonitorId")) 'log the values of col1 and col2
            Log("col2=" & m.Get("DivisionId"))
        Next
    End If
    HttpUtils.Complete = False
End Sub

where is the error? output from the webpage is here

 
Last edited:
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…