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. jeronimovilar2

    jeronimovilar2 Member Licensed User

    Update?

    no :(

    ------------------------------------------------
    new ASP (JASON_UTIL.ASP) code - SELECT is ok:
    <%
    Function QueryToJSON(dbc, sql)
    Dim rs, jsa
    Set dbc = Server.CreateObject("adodb.connection")
    dbc.CursorLocation = 3
    dbc.open "provider=SQLOLEDB;server=(local);Database=db","sa","pwd"
    Set jsa = jsArray()
    If mid(sql,1,6) = "update" then
    dbc.Execute(sql)
    else
    Set rs = dbc.Execute(sql)
    While Not (rs.EOF Or rs.BOF)
    Set jsa(Null) = jsObject()
    For Each col In rs.Fields
    jsa(Null)(col.Name) = col.Value
    Next
    rs.MoveNext
    Wend
    End If
    dbc.close
    Set QueryToJSON = jsa
    End Function
    %>
    --------------------------
    browser (ok):
    http://127.0.0.1/base3.asp?query=update table set J3=1 Where Numero=1
    the table is updated

    ---------------------------------
    B4a (no error), but not updated:
    SQL = "query=update wCadBateria set J3=1 Where Numero=1"
    HttpUtils.PostString("UPDATE", ServerUrl, SQL)

    If Job = "UPDATE" Then
    UpDate = True
    End If
    ---------------------------------

    :sign0085:
     
  2. jeronimovilar2

    jeronimovilar2 Member Licensed User

    UPDATE ok

    sorry.

    The error is in another string with blanks

    " ...where n=1 and F = 'Fase 1' "

    i´ll change the " " for "%20".

    thanks
     
  3. ThePuiu

    ThePuiu Active Member Licensed User

    i try to use this code (from post #1), but after I added the two files (HttpUtils and HttpUtilsService) to my project and tried to compile it I received the following error:
    Compiling code. 0.04
    Compiling layouts code. 0.00
    Generating R file. 0.22
    Compiling generated Java code. Error
    B4A line: 60
    HttpUtilsService.PostBytes = Data
    javac 1.6.0_27
    src\natura2000\mmare\httputils.java:137: incompatible types
    found : natura2000.mmare.data
    required: byte[]
    mostCurrent._httputilsservice._postbytes = mostCurrent._data;
    ^
    1 error

    What am I doing wrong?
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    How is Data defined?
     
  5. ThePuiu

    ThePuiu Active Member Licensed User

    I had an activity called Data ... but after I renamed it everything is ok!
    Seem to be mutually each other...
     
  6. begale

    begale Member Licensed User

    Connection MS SQL

    It is possible to make a connection from Android device to a Microsoft SQL server without using ASP, but with a library ?

    Thank you
     
  7. Erel

    Erel Administrator Staff Member Licensed User

    I'm afraid that it is not possible.
     
  8. yamohsen

    yamohsen New Member

    Database Error:

    Hey Guys, I just copied the asp.net code and pasted in a file with my Database credentials. However I get the following error:

    :sign0085:

    Error occurred. Query=select * from table_1
    System.Data.SqlClient.SqlException: Login failed for user 'uact'.
    at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
    at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
    at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
    at System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean enlistOK)
    at System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, Int64 timerExpire, SqlConnection owningObject)
    at System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(String host, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, Int64 timerStart)
    at System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance)
    at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance)
    at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection)
    at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options)
    at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject)
    at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject)
    at System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject)
    at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)
    at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
    at System.Data.SqlClient.SqlConnection.Open()
    at ASP.test_aspx.Page_Load(Object sender, EventArgs ec)

    -------------------------------------------------------------------------

    Any idea what can I do about it ??? :sign0104:
     
  9. Erel

    Erel Administrator Staff Member Licensed User

    For some reason you appear as an unlicensed user in the forum. Please contact support@basic4ppc.com in order to fix it.
     
  10. ashiqjinnah

    ashiqjinnah New Member Licensed User

    NWs

    I am an absolute beginner of android devolopment now i need to connect sql server to basic4android last day i wl try with the code as shown above but it have some errors and also i try to connect sql server using mssql library mssql library got from this website with mssql library some post are there they ask try the code following below for connecting sql server

    basic4android code :

    Dim a As MSSQL
    Dim L As List
    a.setDatabase("server ipnumber (not name)","databasename","username","password")
    L=a.Query("select * from tablename where keyname='xx'")

    but the progrm pause on the line begin with L=a.Query.....

    friends any one can other idea to connect sql server pls post

    or

    Attach a sample webservise file
    pls help friends.....
     
  11. Erel

    Erel Administrator Staff Member Licensed User

    This thread is not about mssql library. Please start a new thread for this question.

    If you like you can post the error you got when trying this example.
     
  12. Erel

    Erel Administrator Staff Member Licensed User

    This thread is about using an ASP .Net web service to connect to a MS SQL database. I don't think that it is related to your question.
     
  13. alienhunter

    alienhunter Active Member Licensed User

    :sign0161: sorry i will move this question
     
  14. kamalkishor

    kamalkishor Member Licensed User

    Problem While creating login Page

    Hi,


    i have used the following code

    '*********************************************************

    Sub BtnLogin_Click
    Dim tempEmailstring As String
    Dim ExecQuery As String
    Dim sqlQuery As String
    Dim Md As MessageDigest
    Dim ByteCon As ByteConverter
    Dim PassWordHash() As Byte
    Dim IntLName As Int
    Dim IntPasswordConfirmation As String
    Dim tempstringofemail As String
    Dim tempstring0fpass As String
    Dim Strngemail As String
    Dim stringpassword As String
    Dim sqlstring As String
    Dim qurystring As String
    Dim loopstring As String
    Dim cursorcheck As Cursor

    tempEmailstring = EdtTxtEmailAdress.Text

    If EdtTxtEmailAdress.Text = "" Then
    Msgbox("Please Enter Your Email Id","Message")
    Return
    End If

    If EdtTxtEmailAdress.Text <> "" Then
    Dim matcher1 As Matcher
    matcher1 = Regex.Matcher("\w+@\w+\.\w+", EdtTxtEmailAdress.Text)
    If matcher1.Find = False Then
    Msgbox("invalid format","email")
    Return
    End If
    End If

    Dim temppwdstring As String
    temppwdstring = EdtTxtPassword.Text

    If temppwdstring = "" Then
    Msgbox("Please Enter Your Password","Message")
    Return
    End If

    IntLName = temppwdstring.Length()

    PassWordHash = Md.GetMessageDigest(temppwdstring.GetBytes("UTF8"),"MD5")
    Dim md5string As String
    md5string = ByteCon.HexFromBytes(PassWordHash)

    ExecuteRemoteQuery("Select customers_email_address,customers_password FROM cust where customers_email_address ='" & tempEmailstring & "' and customers_password ='" & md5string &"' ",taskiddd)

    End Sub
    Sub ExecuteRemoteQuery(Query As String, TaskId As Int)
    Dim req As HttpRequest
    req.InitializePost2("http://www.siliconsoftwares.in/store/admin/tt.php?user=silicons_store&pass=modem123pentium&db_name=silicons_store", Query.GetBytes("UTF8"))
    HttpCl.Execute(req, TaskId)


    End Sub
    Sub HttpCl_ResponseSuccess (Response As HttpResponse, TaskId As Int)
    Dim res As String
    res = Response.GetString("UTF8")
    Dim parser As JSONParser
    parser.Initialize(res)
    Dim l As List
    l = parser.NextArray
    If l.Size > 0 Then

    Msgbox("login successfully","Message")
    End If
    Else
    Msgbox("Invalid username or password","Message")

    Response.Release
    End Sub
    Sub HttpCl_ResponseError (Response As HttpResponse, Reason As String, StatusCode As Int, TaskId As Int)


    If Response <> Null Then
    Response.Release
    Else
    Msgbox("invalid password or Email","Message")
    End If

    End Sub

    '*******************************************************
    i want to add check on login page .whether the user registered or not .so let me know how it possible by using webservices and mysql database on server. any help or sugestion is appriciated..:sign0085:
     
  15. qawi

    qawi New Member

    Please help my error

    Hi,

    I stuck here to make my project.... please help me to solve my error :BangHead:

    Error occurred. Query=
    System.InvalidOperationException: ExecuteReader: CommandText property has not been initialized
    at System.Data.SqlClient.SqlCommand.ValidateCommand(String method, Boolean async)
    at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
    at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
    at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
    at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior)
    at ASP.test1_aspx.Page_Load(Object sender, EventArgs ec)

    please help me :sign0085:
    i not good in english :sign0089:
     
  16. Erel

    Erel Administrator Staff Member Licensed User

    For some reason you appear as an unlicensed user in the forum. Please contact support@basic4ppc.com in order to fix it.
     
  17. jack007

    jack007 New Member Licensed User

    Well done

    After appropriate modifications, the example code can run very well.
    Look forward to more and better.
     
  18. jalle007

    jalle007 Active Member Licensed User

    I have web service up and running on MSSQL database.
    Tested in web browser and its working
    http://localhost:61343/Default.aspx

    Problem is with Android app since it always returns

    HttpUtils.IsSuccess(ServerUrl) = false

    and logcat contains this
    What should I do ?
     
  19. Erel

    Erel Administrator Staff Member Licensed User

    localhost points to the device not to the computer. Are you using an emulator or a real device?
     
  20. jalle007

    jalle007 Active Member Licensed User

    I tried both.
    The device is on the same netowrk as localhost (PC)
    I tried entering IP on my device and yes it opens my IIS homepage.

    but whenever i try to call eg:
    http://localhost:59459/ParseTable.aspx
    from code , httputils response with NoSuccess (because it cant see localhost)

    I would really like to test the app working with localhost rather then uploafing the page to remote server...
     
Thread Status:
Not open for further replies.
Loading...
  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