Android Tutorial Connect Android to MS SQL Server Tutorial

Discussion in 'Tutorials & Examples' started by Erel, Dec 11, 2011.

Thread Status:
Not open for further replies.
  1. hdtvirl

    hdtvirl Active Member Licensed User

    Erel, 'rows = parser.NextArray' this is where it stops working, it never get passed the first row and it trows an error, I have tried only passing the exact line you have above and it still crashes, with the same exception regarding the array expected.

    I have used the device side example you posted for the tutorial with no changes (only the code for writing the columns to the log file)

    Once again thanks for your help, it is greatly appreciated.


    Last edited: Feb 8, 2012
  2. hdtvirl

    hdtvirl Active Member Licensed User

    Thanks Erel, it is amazing what a nights sleep will do !!!!!.

    Sorted !!


  3. GiovanniPolese

    GiovanniPolese Active Member Licensed User


    I tried with a real device and connection is accepted, so it seems to be only an emulator problem..
  4. hdtvirl

    hdtvirl Active Member Licensed User

    what would a url look like to invoke a method and them pass a select screen

    I have tried it and keep getting an error backfrom the service.

    eg http// select statement :-select * from table

    where anymethod is the method we are trting to invoke.

    so our HttpUtils.PostString command would look like this.

    HttpUtils.PostString("FetchData", http//, "select * from table").

    Any advise would be appreciated.


  5. Erel

    Erel Administrator Staff Member Licensed User

    You should adhere to the protocol that this specific web service uses.
  6. hdtvirl

    hdtvirl Active Member Licensed User

    Erel, I have tried all of that before I sent the previous reply,

    This command works from the commandline of the browser.

    ServerUrl = "*%20from%20Branches"

    We have embedded this command into our application on the httputils.poststring command.
    ServerUrl = " * from Branches"

    The web service is posting back that there is no command string.

    We have also posted is as ",Select * from Branches.

    None of them work, we also have a webservice method with the sql statment embedded and that works OK.


  7. Erel

    Erel Administrator Staff Member Licensed User

    If you are sending it from the browser then it is not a POST request. It is a GET request.
  8. scarecrow

    scarecrow New Member Licensed User

    Hi, I downloaded this example to learn how it works.
    When I tried to process for the first time, I´ve got a message:

    Error Java Line 275 - JSON Array expected.

    Did I skip something to do before try ?

    I also tried to test my on server, wich returns a valid Json streamer, but error message remais de same.

    I had purchased B4A few hours ago... so I´m :sign0104::sign0104:

    Thanks for any help

    Ops... Problem resolved. I built my own webservice. Thanks anyway.
    Last edited: Feb 17, 2012
  9. lachbus

    lachbus New Member Licensed User

    Apologies for the following noob question, as it's really not an Android problem but more of a problem getting the extensions to run on my (old) Windows 2000 server. I upgraded it from Net 1.1 to Net 2 SP2 (3.5 doesn't work on 2000).
    I then installed WSE 2.0 SP2.

    I still get a compilation error in Line 6:

    Line 4: <%@ Import Namespace="System.Data.SqlClient" %>
    Line 5: <%@ Import Namespace="System.IO" %>
    Line 6: <%@ Import Namespace="System.Web.Script.Serialization" %>

    I guess the extensions are somehow not installed or enabled? There's no bin directory under C:\Inetpub\wwwroot.

    As I say, it's not really Erel's or Androids thing, just my noobishness to running ASP.NET scripts. But just in case you have encounteded the same problem or have a suggestion, I'd love to hear it.

    Thanks, Stephan
  10. lachbus

    lachbus New Member Licensed User

    OK, I figured that out:
    1. I had installed WSE (Web Service ENHANCEMENTS). This is not the same as Web Service EXTENSIONS. I figured out that installing Ajax (ASPAJAXExtSetup.msi) will install the extensions.
    2. It still didn't work... But now I could actually find the System.Web.Extensions.dll in the Ajax directory. So I made a bin folder as Erel says, and copied this in there. Voila! It finally works...

    However, while I was digging around, I came across people bitching that copying things into BIN folders is bad practice... Well, another bridge to cross some day in the future.
    Thanks for reading, Stephan
  11. bjf

    bjf Member Licensed User

    aspx connect string

    Probably an idiotic question but where is the actual server to witch to connect specified?

    EDIT, added info in connect string
    Last edited: Feb 16, 2012
  12. jegadk

    jegadk Member Licensed User

  13. scarecrow

    scarecrow New Member Licensed User

    Hi All,
    Here is another problem.


    I´m testing HttpUtils.PostString and it works fine when I send an url without parameters.

    Before test in b4a, I sent in browser:


    By default this url, without any parameters, returns:

    [{"Col1":"1","Col2":"Laguinho com Ilha do Marcelo Cid"},{"Col1":"11","Col2":"Lago 1 do Tioayres"},{"Col1":"12","Col2":"Laguinho do Guizilini"},{"Col1":"13","Col2":"Laguinho do Edmilson"},{"Col1":"19","Col2":"Laguinho do Fernando Almeida"},{"Col1":"20","Col2":"Laguinho do Alonso"},{"Col1":"21","Col2":"Laguinho do Luís Lavia"},{"Col1":"26","Col2":"Lago do Piccirilli"},{"Col1":"27","Col2":"Lago da Vanessa Elisa"},{"Col1":"29","Col2":"Laguinho do Groo"},{"Col1":"30","Col2":""},{"Col1":"31","Col2":"Laguinho do Silvio Orsolin"},{"Col1":"32","Col2":""},{"Col1":"33","Col2":"laguinho da Rita"},{"Col1":"34","Col2":""},{"Col1":"39","Col2":"AINDA NAO CONSTRUI. DAI TER INICIADO MINHA CONTA"},{"Col1":"40","Col2":"lago da suzana"},{"Col1":"41","Col2":""},{"Col1":"42","Col2":"Laginho do Rodrigo"},{"Col1":"43","Col2":""}]

    And when I try this url on b4a, like this:

    HttpUtils.PostString("", "http://myip/example.aspx", "")

    It works fine too !!

    Here is a partial result, in b4a log:

    Rows #0
    col2=Laguinho com Ilha do Marcelo Cid
    Rows #1
    col2=Lago 1 do Tioayres
    Rows #2
    col2=Laguinho do Guizilini
    Rows #3
    col2=Laguinho do Edmilson
    Rows #4
    col2=Laguinho do Fernando Almeida

    Now, problems...

    Problem 1.

    If I pass a parameter to a URL, like this:

    HttpUtils.PostString("", "http://myip/example.aspx?query=Select * from Mylake", "")
    I receive an error message:

    java.lang.IllegalArgumentException: Illegal character in query at index 56:

    Problem 2.

    I tried the same example, but changing “ “ to %20, like this:

    HttpUtils.PostString("", "http://myip/example.aspx?query=Select%20*%20from%20Mylake", "")

    And had no errors message, but I doesn´t work, here is log:

    Starting Job:
    ** Activity (main) Resume ** ** Service (httputilsservice) Create ** ** Service (httputilsservice) Start ** ** Service (httputilsservice) Destroy **


    All urls work fine at browser, my aspx page recognizes and work with this 3 types of query:

    http://myip/example.aspx?query=Select * from Mylake
    http://myip/example.aspx?query=Select * from Mylake

    At all of tests in browser, there´s a response.write that sends a result mentioned above.

    Any ideas to solve problem 1 and problem 2 ?

    Thank you.
  14. hdtvirl

    hdtvirl Active Member Licensed User

    I had exactly the same problem and Erel did give me the answer straight away

    You have to include the name of the server side sql string in your request, as below.

    JSON_RunSQLStatement is the medthod.

    and the whole Request and paramaeters string looks like this

    ServerUrl =

    strSQL = "Select * from tbl_customers"

    Sqlstr is the server side sql string and this is what you need to fill.

    HttpUtils.PostString("Job1", ServerUrl,"Sqlstr=" & strSQL)

    this did the trick for me.

    Bestof Luck.


  15. mo3tez

    mo3tez New Member

    can this be done using PHP?
  16. scarecrow

    scarecrow New Member Licensed User

  17. scarecrow

    scarecrow New Member Licensed User

    Yes. I don´t know how to do using PHP, but I don´t see any reasons that could not work.
  18. Erel

    Erel Administrator Staff Member Licensed User

  19. JohnC

    JohnC Well-Known Member Licensed User

    ASP.Net (VB)

    Hey Erel,

    Is there any chance you can create a VB version of the server ASP.NET page in the first post of this thread?

    I ask because I am a VB programmer, and I don't quite know how to translate some of the C# code in your ASP.NET server page into VB for ASP.NET.
  20. Erel

    Erel Administrator Staff Member Licensed User

    I'm sorry but I'm not really familiar with VB for ASP.Net.
    Maybe someone else will be able to help you.
Thread Status:
Not open for further replies.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice