Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more: , +
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
protected override void OnAppearing()
        {
            base.OnAppearing();


            //MY SQL

            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<user>();
            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?

What I have tried:

C#
<pre> 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<user>();
            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();

        }
Posted

1 solution

You don't listen much, do you? As stated in your other copy of this same question, for a Xamarin app, you should NOT be connecting directly to a database engine. You SHOULD be calling a web service that sits in front of your SQL Server where the web service is doing the database work for you and returning results back to the client. Your Xamarin app should be calling the web service, not the database.

Your other copy of the question: Connection string to MS SQL database android/iOS app[^]

Next, a little pet peeve of mine. You do not have to specify the port number in the connection string unless your server is not using the standard port number, 1433.
 
Share this answer
 
v2
Comments
Maciej Los 20-Nov-23 12:29pm    
5ed!
Andre Oosthuizen 20-Nov-23 13:48pm    
Doubled +5ed, Answer were given in the others but no, what do we know.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900