xamarin cannot conect to sql server

557 views Asked by At

the application must connect directly to the sql server database and output data from the table

I wrote the following code:

    using Android.App;
using Android.OS;
using Android.Support.V7.App;
using Android.Runtime;
using Android.Widget;
using System.Data.SqlClient;

namespace PrApp4
{
    [Activity(Label = "@string/app_name", Theme = "@style/AppTheme", MainLauncher = true)]
    public class MainActivity : AppCompatActivity
    {
        TextView textView1;
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.activity_main);
            textView1 = FindViewById<TextView>(Resource.Id.textView1);
             string ConString = "Data Source=COMP106-1\\SQLEXPRESS;Initial Catalog=AVTO_SALON;";
            string SqlCom = "select * from Avto";
            using (SqlConnection sqlCon = new SqlConnection(ConString)) { 
                sqlCon.Open();
            SqlCommand cmd = new SqlCommand(SqlCom, sqlCon);
            SqlDataReader reader = cmd.ExecuteReader();
            reader.Read();
            //await DisplayAlert("Уведомление", reader.GetString(1), "ОK");

            textView1.Text = reader.GetString(1);
                //textView2.Text = reader.GetString(3);
            }

        }
    }
}

when you start the application, the following error appears: cannot connect to sql server browser ensure sql server browser has been started

0

There are 0 answers