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:
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
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
VedyujPosted Apr 16, 2025, 10:05 AM
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.
Vishal JoshiPosted Nov 20, 2023, 8:38 AM
Try the below code to build the connection with MS SQL Databaase.
Thanks
Vishal Joshi