Forum Xamarin.Android

How to connect with SQL Server

Hi guys! im new on apps development and im developing a test app for android 4.1 that require connection with SQL Server. The server is online and published on internet. (free hosting).
I used the reference System.Data and a class Connection with the connection string and in the android virtual device it runs very well but when i install the apk in a real device (Nokia x and Samsung Galaxy J1) the connection with SQL server fails in edge, 3g, and wifi network.
I Hope that someone please can help me. (sorry for my bad english)
Here is the code of MainActivity.cs

using System;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;

namespace Master
[Activity(Label = "Master", MainLauncher = true, Icon = "@drawable/icon")]
public class MainActivity : Activity
protected override void OnCreate(Bundle bundle)
Button button = FindViewById(Resource.Id.MyButton);
button.Click += delegate {
SqlCommand cmd = new SqlCommand();
Connection cnn = new Connection();
SqlConnection cn = new SqlConnection(cnn.ReadConnect());
button.Text = string.Format("Connection succesfully");
button.Text = string.Format("Error connect");


  • AndyFlisherAndyFlisher GBBeta, University ✭✭✭✭

    Don't, whilst technically it might work you shouldn't. Build a Web API that exposes that parts of your database that the app needs. Gives you an abstraction and protection layer, and makes you use http calls which are designed to work in poor and low latency connections

Sign In or Register to comment.