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

Muhammad hamid 11 Reputation points
2022-04-26T11:30:46.783+00:00

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.
12,671 questions
{count} votes

4 answers

Sort by: Most helpful
  1. 致远 李 5 Reputation points
    2023-01-19T03:24:05.1433333+00:00

    Has anyone figured this out?

    error message:

    Microsoft.Data.SqlClient.SqlException

    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)

    Infos:

    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!

    1 person found this answer helpful.

  2. Bruce (SqlWork.com) 55,196 Reputation points
    2022-04-26T15:56:21.45+00:00

    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.


  3. S M Hasan 1 Reputation point
    2023-03-06T10:03:26.2933333+00:00

    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

  4. Don Guiruela 0 Reputation points
    2023-08-03T13:26:45.4733333+00:00

    Unlike Windows, Android, afaik, relies on web APIs. You may build your own web-services for this.