I am Not Able to connect .NET MAUI Project with MS SQL Connection.

Muhammad hamid 6 Reputation points

Hi , 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 ,

regards M.Asad.

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
9,827 questions
{count} vote

3 answers

Sort by: Most helpful
  1. Bruce (SqlWork.com) 36,346 Reputation points

    Microsoft.Data.SqlClient is the replacement for System.Data.SqlClient. they have the same api, but the new version is getting the new features. Not sure what you mean when you you say mssqlconnection. in both libraries its (assuming the namespace using)

    using var conn = new SqlConnection(connectionString);
    await conn.OpenAsync();

    your error sounds like you are not using trusted certificates on the sqlserver, so need you need to add TrustServerCertificate=true; to the connection string.

  2. 致远 李 0 Reputation points

    Has anyone figured this out?

    error message:


    Message=A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: SSL Provider, error: 31 - Encryption(ssl/tls) handshake failed)


    Microsoft.Data.SqlClient 5.0.1

    SQL server 2019 developer

    I tried:

    1, put "trustServerCertificate=true" in connectionstring and installed certificates in computer, failed

    2, put "encrypt = false" in connectionstring and put "android:usesCleartextTraffic ="true" " in AndroidManifest.XML , failed

    In Xamarin.Forms using System.Data.SqlClient , sucessfully without any problems.

    In Maui windows platform using Microsoft.Data.SqlClient , sucessfully without any problems.

    If there are any suggesttions or solutions , please let me know!

    Thanks everybody!

  3. S M Hasan 1 Reputation point

    Hi @muhammad hamid
    For SQL Connection you have to use Platform OS specification code , create a file in Windows SQL Connection file and call in your project anywhere using dependency

    public class ExcelToSql : IExcelToSql

    0 comments No comments