Connect to a SQL Database from Android - c#

I want to develop an Android application which would connect to a SQL Database which is already created . We developed this news site :
e-Cmunio. This site is based on a SQL Database that already has a lot of news and stuff in. For now, what we want for our Android app is to connect to that database and show some random news in a listView.
The problem is that I don't know how to connect to it from Android.
I have already read about some WebServices, but I have no idea from where to start.
We ( me and a friend ) are in HighSchool. The site was developed in C#. We are new in Android and java, but we are familiar with algorithms and data structures.
Could you please give me some tutorials and entry-level information about how can we access our DataBase?
Sorry if I hasted your time, but I really have no idea where to start from.

The easiest way is to use PHP to parse ur data to JSon and read that data and parse it in ur Android phone..
SQL to PHP to JSon to read from.
http://www.bin-co.com/php/scripts/sql2json/
Parse JSON to Android
http://www.vogella.com/articles/AndroidJSON/

What you want to do is make a webservice on your server side that connects to your database and returns whatever you want to return in your favorite format(XML / JSON).
Next, on Android(client side) you want to have an AsyncTask to access that webservice and fetch your news and save them to your Android SQLite Database.
Later like you suggested you can load those news from a cursor directly to your listView with a Listview adapter.
You can read about Saving data in SQLite here: http://developer.android.com/training/basics/data-storage/databases.html
You can read about AsyncTask here: http://developer.android.com/reference/android/os/AsyncTask.html

You already have an elaborate answer in connect to sql server from android.
Web services define interface for your website in a standardized way, so that
other websites/applications can access it. It is more extensible and generic solution
then directly accessing server's database.
Simple web service can be just an XML or a JSON file generated after querying your
website with specific parameters. So as an exercise in your case I would implement
handling of specified URL in your C# server code and generate XML file with your
news (query in URL) and then just open your page with this URL on your android app
and read this XML. When your app will become more complex, then you can start moving to
some standard web service solution.

Related

Web service for Laravel

Assume that I have a third-party database application with SDK that can be used to retrieve data out of the database in XML.
On the other side, I have developed a website using Laravel framework of PHP. The website is supposed to display data from the database of the application.
In regards to above I have the following questions:
As far as I understand, I can either store the requested data in my website database or just show it without storing. What technique do you suggest?
How do I achieve xml data transfer from the database server to the website?
Taking into account that I have experience of development in C#, I assume that I have to develop some web-service that would run on the database server, retrieve the required data and send it to my website. So the web-service has to receive the requests from my Laravel website, retrieve data from database server accordingly and pass the xml response to my website that would finally display it. Am I on the right way? If so, could you please guide me on how to code and bind these parts?
Thank you in advance.
I have to agree with #Serge in the comments - there are many ways to do this because it is a very broad question.
My answer was mostly going to deal with how regularly the third party database was going to be updated but judging from your comments, I'm assuming it will be fairly often? In which case, I would likely connect directly to the third party database from your laravel app using the firebird driver found here: https://github.com/jacquestvanzuydam/laravel-firebird (Please note, I have never used this so I cannot comment on it's quality) instead of writing a C# web service. I don't know much about firebird itself but you will likely want to connect using an SSH tunnel or VPN for security reasons.
Then I would either store data in MySQL if you know it isn't likely to change very often (in this case you would use a laravel command, run on a schedule, to pull data out of firebird every [X] days/hours/minutes depending on the data) or, if the data is likely to change on each potential web request, using some form of caching system (redis, memcache, file cache etc) to speed up the web requests.
Sorry if that isn't particularly helpful - if you can provide more information maybe I can help you out further :)
Good luck!

Phonegap Stand alone (Offline) Application

I currently develop one web based software (Like library) (In PHP with MySQL) and now I Plan to develop that for smart phone and desktop. So I came to phonegap for smart phone. but now how can I grab data from my MySQL database to app? is it possible with JSON ? How ?
Other Question is that how can I use that app which develop in Phonegap while device is not connected to internet? My Same problem is with windows based software which I'm going to develop in C#.
Thanks...
Any type of help will appreciated.
to grab data from your MySQL database, you will need to create some PHP controller on your server to which you will send POST/GET requests from your app to retrieve/update data.
to have the app working offline, you must store previously downloaded data within devices database or introduce some caching solution (angular provides one, for example).
You should use GET/POST method in php to return the database result have wrap the whole sql result in json_encode function
i.e
echo json_encode($result);
in your offline storage you can use websql which will store it in your device storage.
since its deprecated you should probably use indexeddb for localstorage.
yes ajax will be most commonly used like $.getJSON(); methods but my favorite is
var jsonp = document.createElement("script");
jsonp.type = "text/javascript";
jsonp.src = "http://foo.com/api/ad?foo_var=4345&callback=displayinfo";
document.getElementsByTagName("body")[0].appendChild(jsonp);
function displayinfo(data) { //do your stuff }

C# WP8 Connect to MySql database

I am struggling to figure out how to connect to a MySql database in my C# Windows Phone 8 application like I can on my desktop application. The reason I am struggling is because it seems I cannot just use the same MySql.Data library that I used on my desktop application. Are there any other libraries that I can use to access my database?
PS. I really don't want to go the PHP route because I will have to have Apache running on y server two and will have to add JSON interfacing two which will not only be a hassle but possibly also waste some processing time and make my application more complex.
PPS. If not possible with MySql, can it be made to work with Microsoft SQL Server or Azure?
EDIT:
If some sort of HTTP interface is my only option, is there some easy existing API or something that I can use to allow SQL data transmission or will I have to create specific PHP(/asp.net or whatever) code for each type request that I am planning to send?

Grabbing MS SQL Server Data for iPhone App?

I have a pre-existing desktop application that draws its information from a Microsoft SQL Server. The desktop application is written in C#/ASP/.NET.
I'd like to take this same data and present it in an iPhone application. What would be the best way to obtain and present the data?
I would recommend writing a web service that exposes the data and then interfacing with this from the iPhone across the network.
Calling web services and making HTTP calls is very easy on the iPhone.
Do you assume your iPhone application will have network access? If so I would go the webservice route as already mentioned. If it's a small database that you want available on the iPhone with out the need to access the internet to retrieve data you could look at converting the SQL Server database into a SQLite database and packaging it with your app.

J2ME communicating with MS-SQL

I am trying to create an integrated project in which I can update MS-SQL's database value using J2ME's application.
But I need more resources/links that let me fully understand how to go about writing implementation for this.
These are the few question in which I've got in mind.
How do I update the data that I've got from J2ME into MSSQL 2005?
How do I retrieve and view the updated value from the database?
How do I send sms to the J2ME's application, as the other application of mine need to send an 'alert' to the j2me app.
Short of writing your own ODBC library for J2ME, I would suggest you look at writing a web service layer over your database which the J2ME application can communicate with over HTTP.

Categories