question

Muhammadhamid-8726 avatar image
1 Vote"
Muhammadhamid-8726 asked WMcRob-5708 commented

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

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.

dotnet-sqlclient
· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@Muhammadhamid-8726, Currently .NET MAUI related question is not supported in Microsoft Q&A, I recommend that you could ask the question in Github.

Thanks for your understanding.


0 Votes 0 ·

Hi, what Android version and what SqlClient version and what SQL Server version are you using? I am facing this issue as well.
Did it happen only on Android? For me it does not happen on Windows, only on Android
I am curious also did you get System.Data.SqlClient to work on Android? Or was it Microsoft.Data.SqlClient?

Thank you.

0 Votes 0 ·

I am also having this issue...has anyone figured this out?

0 Votes 0 ·

1 Answer

Bruce-SqlWork avatar image
0 Votes"
Bruce-SqlWork answered SCAppCo-7151 commented

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.









· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hello and thanks bro , i am using same as you told conn = new SqlConnection(String) and tried Trustcertificatet = true but it is not working still. ??

0 Votes 0 ·
Bruce-SqlWork avatar image Bruce-SqlWork Muhammadhamid-8726 ·

is the sql server configured fr tcp/ip? try this simple powershell script to test your connection string

 $conn = New-Object System.Data.SqlClient.SqlConnection
 $conn.ConnectionString = "Server=MyServer;Database=Sample;Integrated Security=True;TrustServerCertificate=True;"
 $conn.Open()
 $conn.Close()

0 Votes 0 ·
SCAppCo-7151 avatar image SCAppCo-7151 Muhammadhamid-8726 ·

Did you get it working? I am having the same issue with Net Maui and Microsoft.Data.SQLClient. I cannot get it to connect. I keep getting the following two errors... I am trying to connect to a SQL Server on our local network, and I have a valid DigiCert installed. I see the Cert with OpenSSL.

Also - everything works when debugging as Windows Machine, but it always fails when debugging as Android device. Using Visual Studio 2022.


Caused by: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.

A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: TCP Provider, error: 35 - An internal exception was caught)



0 Votes 0 ·

I am having the same issue with Net Maui and Microsoft.Data.SQLClient. I cannot get it to connect. I keep getting the following two errors... I am trying to connect to a SQL Server on our local network, and I have a valid DigiCert installed. I see the Cert with OpenSSL.

Also - everything works when debugging as Windows Machine, but it always fails when debugging as Android device. Using Visual Studio 2022.


Caused by: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.

A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: TCP Provider, error: 35 - An internal exception was caught)

0 Votes 0 ·