1

I have a database in MS SQL 2014 containing my tables like login user table and data of user table.

Now I make the login app design for it, but how can I connect with MS SQL 2014 from Android?

mkrieger1
  • 19,194
  • 5
  • 54
  • 65

2 Answers2

0

You are looking for this on REST API communication stackoverflow.com/a/26573636/2413303 and if you want to look into something more advanced, here is a nifty project with sources and everything github.com/vyshane/rex-weather and don't forget the official guide developer.android.com/training/index.html and also use Otto vogella.com/tutorials/JavaLibrary-EventBusOtto/article.html and ButterKnife tikalk.com/

Using Retrofit in Android

Community
  • 1
  • 1
Ahmad Aghazadeh
  • 16,571
  • 12
  • 101
  • 98
0

I try to explain the basic Rest API communication below. Please note that below code is only an example and there are a lot to do in server-side for security, maintability, testability or any other architectural issues.

Firstly, you should create a service layer server using a server-side language like php, java, c# or others. Considering you use C# MVC. You can create a Web API project query your db and return the data as Json string which could easily be parsed in your Android App. Here is a sample;

public string GetRecords()
    {
        using (var context = new TestEntities())
        {
            return JsonConvert.SerializeObject(context.Records.ToList());
        }
    }

Then; you publish this API to IIS so that it is accessible through an URL like "http://localhost/Home/GetRecords".

In your Android application, you can call this URL via HTTP get or post to get the result as Json string. There are lots of sources how to call Rest API in Android such as this.

Then, you can parse the Json string to Android model and manipulate according to your needs.

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
ali
  • 1,301
  • 10
  • 12
  • hi there i have write a website project in asp.net and i coonect ms sql to that wesite for log in and data operations and also i hosted it online but now i create an app and want to log in with those cardinals? – Souls Hunter May 16 '16 at 12:37
  • @SoulsHunter The server side operations are very similar in web applications and REST APIs. The difference is that in websites you are serving the end user by using aspx, cshtml, or HTML pages. In Rest APIs or other Web Service technologies, you are presenting data to other devices, systems or interfaces. I believe, you should visit more examples on Web Services, REST API Communication to really understand your needs and solutions. – ali May 16 '16 at 12:45
  • bro can i have some exmple code for connection with a sql db hosted online i'm native to android dev and started dev last 20 days please if a possible code is given it will be more helful for me please – Souls Hunter May 17 '16 at 12:11