Goran Bibic

Goran Bibic

  • 481
  • 2.9k
  • 199.5k

MS SQL database connection xamarin

Nov 20 2023 7:33 AM

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<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();
        }

My code for MS SQL database with error

 

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

        }

Some help?

Thank you


Answers (1)