Android Tutorial Connect Android to MS SQL Server Tutorial

Status
Not open for further replies.

Kwame Twum

Active Member
Licensed User
Longtime User
Hi everyone, after querying a MSSQL database, I retrieve a JSON string which I format to suit my app.
However, when a record contains an image, say -
B4X:
j1.PostString(my_serva,"SELECT u_name, age, dp FROM gamers") 'dp is the field for images
- the JobDone is called after a very long time... (sometimes more than 1 min).

But if I query without asking for an image, say -
B4X:
j1.PostString(my_serva,"SELECT u_name, age FROM gamers")
- it's superfast.

The images in the database are very small too, all are 146px x96px and less than 30KB
What could be the issue?
 

Kwame Twum

Active Member
Licensed User
Longtime User
Erel, I'm rather retrieving it from the JSON string not adding the image to it..
 

Kwame Twum

Active Member
Licensed User
Longtime User
Erel, I think you're getting me wrong... I'm not sending data into the database... I'm rather retrieving data from it...
The resulting JSON is what I'm structuring...
I mean the data takes a longer time to be retrieved when it contains an image... Eventually, it does appear. But it takes too long.

The images are pushed into the database with a desktop app created with .NET
 
Last edited:

Kwame Twum

Active Member
Licensed User
Longtime User
Yes Erel, when the data finally get's to the app (after about a minute), the image is in the JSON string alright
 

Kwame Twum

Active Member
Licensed User
Longtime User
Thanks Erel, but that'll mean I have to place the images on the server directly instead of in the database right?

This is the actual code that stores the image on the server.. It's in VB.Net

B4X:
        Call connect() 'This opens a connection to the MSSQL server
        Dim cmdd As New SqlCommand
        cmdd.Connection = con
        cmdd.CommandText = "update gamers set dp = @img where u_name= '" & TextBox1.Text & "'"
        cmdd.Parameters.Add("@img", SqlDbType.Image).Value = File.ReadAllBytes(mii) 'mii contains the file path of the image selected
        con.Open()
        If cmdd.ExecuteNonQuery() = 1 Then
            MsgBox("Sent")
        End If
        con.Close()

I'm wondering what encoding that is...
 

Kwame Twum

Active Member
Licensed User
Longtime User
I believed that was handled automatically... I've always thought that when data is retrieved in the manner I'm requesting, it's always returned as a string, then parsed by the JSON library by calling:
B4X:
      JSONParser1.Initialize(Job.GetString)

Am I wrong?
 

Kwame Twum

Active Member
Licensed User
Longtime User
Erel, I tried it and it's a really long string indeed:
I changed the query to return only the image
B4X:
j1.PostString(my_serva,"SELECT dp FROM gamers WHERE age=1")
Result looked something like[{"dp":[255,216,225.............. (I've shortened it to save space on the thread)
and it was truncated.
 

Kwame Twum

Active Member
Licensed User
Longtime User
Thanks Erel, but all what you're saying refers to the process of retrieving the image after the JobString returns...

However, I just wanted to know why it took so long to return when it contained an image... and also if I could store the images in a manner that could speed reading from the database.

Once again, thanks.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…