question

Muhammadhamid-8726 avatar image
1 Vote"
Muhammadhamid-8726 asked JanSeris-5133 published

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
· 2
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 ·

1 Answer

Bruce-SqlWork avatar image
0 Votes"
Bruce-SqlWork answered Bruce-SqlWork 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.









· 2
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 ·