SQL Server database and Android - android

I am connecting to a SQL Server database with the Android device. Yes I know not very advisable but everything works fine except ... well it's slow.
Here is what I do:
open conection
download table by table the data I need from the server database (with a connector I found online)
insert table by table into sqlite
I only select what I need; there are about 12 tables and some have like 300 items
Then I send some data to the server database (the select from 2 tables)
How could I make the thing work faster without using web services? (if possible)
If I do use web services will it be faster?
Thanks a lot in advance
PS: I know there are the risks about accessing the DB that way they are not relevant in this case.

Do you really need to replicate the same schema on Android? Try to narrow it down to only the essential data, and maybe create a new 'light' schema for the Android app. Do not use select *, only get the columns you need. Even with this, the first sync will probably be relatively slow. After you sync once, you can only get the newest items, so it should go faster.
If you want to use a webservice, you will have to rethink your model: instead of syncing tables with rows, you will work with entities (customers, orders, etc.). If you transfer the same amount of data, a webservice won't be faster, it can even be slower. The benefits of a webservice are that you don't have to know the exact schema on the server, so you don't need to change your app if it is changed (as long as it has all the data you need, of course); and that thinking in terms of a service will make you only use the data you need, making the whole interaction faster. And, it works over the Web, of course, so it will work with proxies, NAT, and what not.

After the initial sync, you could code your android app to retain the data in sqllite and only download the differences/changes on the next connection.
Depending on how changeable your data is on the server, this method could reduce you sync time.

Related

How Can I Create a Database Accessed By windows and Android

I have been looking and searching for this whole day, so i want to create a database which can be accessed by both computer and smartphone, is there a way to do it, and how ?
Sorry For Beginner Question, Thanks in Advance
Ok, the first thing you should do is to define the type of database
that you want. You can build SQL or No-SQL database. For the most
part I would suggest no-sql so something like MongoDB could do, but you can always do mySQL. As
for accessing that db with anything actually, you need application
layer around it. You see, database acts as just a huge data
container thus it should not be used for any other logic.
Now, lets talk about application layer. To be more precise - about posting/updating/retrieving data from db. You should research something about RESTApi or GraphQL concepts as they are used to make communication between your app and your db which is hosted on a server (I deliberately did not talk about how you can build an app because I assumed you already know this one).
THE POINT: The most important concept to wrap your head around is how you can access the db you make not the type or tech used to build it. (Even though this is important too)
Good luck!
The better way to do this its creating a web service, so your app will talk to this web service, the web service will talk to your database and retrieve the results to your app (this can be done using HTTP protocol's APIs like Volley for android) and its a secure way to do it.
You can connect your application direct to your database granting external access, but this is a specif configuration according to your database (mysql, ms sql, etc.) and its not recommended.
You can think in the same way to the computer(s) that will access your database, except if this computer(s) is in the same network which the computer that your database is hosted in, in this last case, the program in this computer (which will access the database) can access it directly (you need to setup the database to permit this and this setting is diferent according to your database).

Mobile DB app off line from internet

I have an architecture question. If you have a web app that is storing information on a DB server, theoretically, I should be able to use the middle tier logic for a mobile app. When the mobile app starts it can connect and populate a local SQLite DB or use JSON to store information within the mobile app. What if the mobile app also needs to work in off-line mode? Do you have it sync the next time it is connected? Do you have the mobile pull down and populate a complete DB or so it available in off-line? What are the best ways to architect a mobile app that has to go from on-line to off-line?
The simplest solution would be to put a "LastEdited" column into every table in your database and then pull query all the data which has updated since the last sync ( and you can perform a check on the index to detirmine if you need to update or insert into your own local cache. )
The ability to delete rows should actually be limited to a boolean "isDeleted" flag in this case to keep the sync process nice and simple.
If you have then the ability to edit or create rows from your app then you should keep a local table of changes to sync when you can go online and may have to implement some form of "merge" logic.
Several things you need to consider.
If your app is read only, you should implement a 'delta sync' logic in your local d. Keep a timestamp of last sync and get updates from your server. Of course, you need to consider the local db size in getting too large.
If you app is read/write, when working offline, you need to consider the two way sync especially when same record can be updated in different devices/users.

Android | Update sqlite from mysql or update app with newer sqlite db?

Still newish to Android.
I need some advise, Should I
1. have a local sqlite DB, and have the app check for new records uptop in a mysql DB
OR
2. Publish my app with a full sqlite DB. When ever I insert new records to the full sql lite DB then publish updates?
I've been scouring the internet for some guidance. Since I am still newer to Android I wonder the difficulty in making #1 work (since I'll have to gen the php code as well).
My suggestion is:
If it's only 200 records now, it doesn't really matter if you preload it or get it from a web service (getting the data will be very quick). Usually preloaded database is better when there is a lot of data and you don't want the user to wait to long before using your App.
On the other hand if there is a lot of data, it will increase the apk size.
Create a web service method for updating the data from the server.
Create a web service method which indicate the client to delete some rows (I dont know what your application does, but usually it's needed)
What do you mean by 'uptop'? Assuming you mean 'online via an API'.
depending on the nature of your data (is is mission critical? what's the risks if it is stale? etc), it's good practice to pack static data with the app that can be referenced by the app much sooner than the updated data...the updated data is a task you run to update that stale data, and perhaps continue to run periodically to keep it updated.
It's bad practice to pack a SQLite db itself in an app, as some manufacturers do their own thing with the implementation of SQLite itself. So pack the SQL as text and create a fresh DB on the device with that.

What would I need to do in order to connect to a central database with Android?

I'm about to build a GPS Spot Finder application with Android and I am trying to decide what requirements are feasible and what aren't. The app would enable users to essentially add different spots on a Google Map. One of the problems would be fetching the data, adding new spots, etc, etc. This, of course would mean the database would have to be online and it would have to be central. My question is, what kind technologies would I need to make this happen? I am mostly familiar with XAMPP, PHPMyAdmin and the like. Can I just use that and connect Android to the database? I assume I would not need to create a website...just the database?
What different approaches can I take with this? Be great if people can point me in the right direction.
Sorry if I don't make any sense and if this type of question is inappropriate for Stackoverflow :S
Create a website to access the database locally, and have Android send requests to the website.
If users are adding spots to a map that only they see, then it makes sense to keep the data local to Android using a built-in database (SQLite). That looks like
ANDROID -> DATABASE
You can read up about SQLite options here.
If users need to see all the spots added by all other users, or even a subset of spots added by users, then you need a web service to handle queries to the database: Connect to a remote database...online database
ANDROID -> HTTP -> APPLICATION SERVER -> DATABASE
Not only is trying to interface directly to a database less stable, but it may pose risks in terms of security and accessibility.
Never never use a database driver across an Internet connection, for any database, for any platform, for any client, anywhere. That goes double for mobile. Database drivers are designed for LAN operations and are not designed for flaky/intermittent connections or high latency.
Additionally, Android does not come with built in clients to access databases such as MySQL. So while it may seem like more work to run a web service somewhere, you will actually be way better off than trying to do things directly with a database. Here is a tutorial showing how to interface these two.
There is a hidden benefit to using html routes. You will need a programming mindset to think through what type of data is being sent in the POST and what is being retrieved in the GET. This alone will improve your application architecture and results.
Why not try using something that is already built into android like SQLite? Save the coordinates of these "spots" into a database through there. This way, everything is local, and should be speedy. Unless, one of your features is to share spots with other users? You can still send these "spots" through different methods other than having a central database.
And yes, you just need an open database, not a website, exactly. You could technically host a database from your home computer, but I do not suggest it.
If you are looking at storing the data in your users mobile nothing better than built in SQLLite.
If you are looking at centralized database to store information, Parse.com is a easy and better way to store your user application data in centralized repository.
Parse.com is not exactly a SQL based database, However you can create table , insert / update and retrieve rows from android.
Best part is it is free upto 1GB. They claim 400,000 apps are built on Parse.com. I have used few of my application typically for user management worked great for me.

approach for synching android app database with server db?

I'm developing an Android app as a "proof of concept" for our company. If they like it and think it's worth investing, then we'll move on to bigger things. I'm trying to figure out the best/most practical approach for this.....the basics of the app will connect to our DB and display information regarding a specific customer. For now, let's say we will only pull data from 3-4 tables (but there could be 10+ in the future). If the app doesn't have an internet connection then it should use the local DB. What is the best approach for this? Here's what I was thinking and would like some input/suggestions if possible:
1.) app runs checks internet connection. If exists, check db version (how, through a web service?)..if server db is newer, get latest data. If no internet, use local db.
2.) app parses data and displays it.
If this is correct, then there could be no modifications to the web service that would add fields to a result without changing the app as well. Is there a way for an app to parse fields regardless of how many fields there are?
I've read and walked through the tutorial on google with databases and such (Notepad tutorial) but it seems like the column names are all hard-coded in the parsing class, which I was hoping to avoid.
Sorry if this is confusing but I know I need my app to use a local db to read data, I also know that the app must get data from the server when it can (via onCreate or a refresh button) and copy it locally....Copying it locally is the part I'm having trouble understanding I guess....is there no way of saying "go out and get this result and display it", knowing that those results could mean 5 fields the first time or 1 the next.
Any help/guidance is greatly appreciated!
You probably want to use a SQLLite DB to store your data locally, a ContentProvider to provide CRUD access to the db, and a SyncAdapter to sync with your server when possible. The Sync Adapter also writes to the DB via the ContentProvider. See the SampleSyncAdapter sample in the SDK for an example of how this works. You will be implementing your own ContentProvider, but the sample just uses Android's supplied Contacts ContentProvider.
http://developer.android.com/resources/samples/SampleSyncAdapter/index.html

Categories

Resources