I have two online database for test mobile app
1) MYSQL (work from workbench and from xamarin app)
2) MS SQL (work from ssms, not work from app)
Both database are online and try to connect online from another network and mobile device
Error is: System.InvalidOperationException: 'Internal connection fatal error.'
My code to my sql and work:
C#
string connectionString = "Server=MYIPADRESS;Port=3306;Database=DatabaseName;Uid=admin;Pwd=password;";
var koneksi = new MySqlConnection(connectionString);
string queryString = " SELECT ime from drzave ";
var cmd = new MySqlCommand(queryString, koneksi);
koneksi.Open();
var rd = cmd.ExecuteReader();
users = new List();
while (rd.Read())
{
users.Add(new user
{
Osoba = rd.IsDBNull(rd.GetOrdinal("ime")) ? string.Empty : rd.GetString(rd.GetOrdinal("ime")),
}
);
}
rd.Close();
listview_users.ItemsSource = users;
koneksi.Close();
}My code for MS SQL database with error
C#
protected override void OnAppearing()
{
base.OnAppearing();
string connectionString = "Data Source=MYIPADRESS,1433;Initial Catalog=DatabaseName;User ID=admin;Password=password;";
string queryString = "SELECT ime FROM dbo.drzave";
SqlConnection koneksi = new SqlConnection(connectionString);
SqlCommand cmd = new SqlCommand(queryString, koneksi);
koneksi.Open();
var rd = cmd.ExecuteReader();
users = new List();
while (rd.Read())
{
users.Add(new user
{
Osoba = rd.IsDBNull(rd.GetOrdinal("ime")) ? string.Empty : rd.GetString(rd.GetOrdinal("ime")),
}
);
}
rd.Close();
listview_users.ItemsSource = users;
koneksi.Close();
}Some help?
Thank you

Vishal JoshiRank #377 · 6.7K reputationPosted Nov 20, 2023, 3:38 AM EST
Try the below code to build the connection with MS SQL Databaase.
_connectionStr = new MySqlConnectionStringBuilder { Server = "IP Address", Database = myDatabase, UserID = myUserName, Password = myPassword, ConnectionTimeout=60, Port = 3306, AllowZeroDateTime = true }; _con = new MySqlConnection(_connectionStr.ConnectionString); try { _con.Open(); } catch { Console.WriteLine("Error, help i can't get connected!"); }Thanks
Vishal Joshi
Vedyuj22 reputationPosted Apr 16, 2025, 6:05 AM EDT
If you're working with MS SQL database connection in Xamarin, make sure to properly configure your connection string and use async calls to avoid UI thread blocking. Also, it's worth considering whether MS SQL is the best fit for your mobile app. Depending on your app’s architecture and offline capabilities, you might want to look into other options like Realm or SQLite. This comparison on database android gives a good overview of what's best for mobile environments. Performance and ease of integration can vary a lot depending on your use case.