1

I am Using MS SQL in .NET Maui Project and I am not able to get connected . the problem is that when i am using System.data.Sqlclient it is not showing me mssqlconnection object so I tried with Microsoft.data.mssqlclient and this time it is giving error "Connection was established but there is problem during pre login handshake " can you please give me any suggestion ,

string myconnect = "Data Source =hostname\\servername; " +
       "Initial catalog =dbase;User ID=user;Password=pass;";  
    SqlConnection MyConnection = new SqlConnection (myconnect);
    MyConnection.Open();
    SqlCommand mycmd = new SqlCommand();
    mycmd.CommandType = CommandType.Text;
    mycmd.CommandText = "select * from logins where UserName =@user and PassWord=@pass ";
    mycmd.Parameters.AddWithValue("user", txtUser.Text);
    mycmd.Parameters.AddWithValue("pass", txtPass.Text);
    mycmd.Connection = MyConnection;
    SqlDataReader myread = mycmd.ExecuteReader();
    if (myread.Read())
    {
        DisplayAlert("TEST", "PasswordOK", "Press");
    }
    else
    {
        DisplayAlert("TEST", "Password Is Bad", "Press");
    }
Yasseralim
  • 25
  • 1

1 Answers1

1

Use Microsoft.Data.SqlClient package from NuGet instead of System.Data.SqlClient.

See this other answer.

James Risner
  • 5,451
  • 11
  • 25
  • 47