Hello
have you tried to connect to this SQL Server using SSMS ? See if you get the same error message. If that´s the case then make sure that firewall in not blocking any SQL ports between client and server
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I am getting below exception for database connection with MAUI android emulator. Can you please help us to resolve issue.
Microsoft.Data.SqlClient.SqlException: '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)'
My connection string:
connString = "Data Source=;Database=;User Id=;Password=***;Encrypt=True;TrustServerCertificate=True";
Exception:
- $exception {Microsoft.Data.SqlClient.SqlException (0x80131904): 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)
---> System.Security.Authentication.AuthenticationException: Authentication failed, see inner exception.
---> Interop+AndroidCrypto+SslException: Exception of type 'Interop+AndroidCrypto+SslException' was thrown.
--- End of inner exception stack trace ---
at System.Net.Security.SslStream.<ForceAuthenticationAsync>d__146`1[[System.Net.Security.SyncReadWriteAdapter, System.Net.Security, Version=7.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a]].MoveNext()
at System.Net.Security.SslStream.AuthenticateAsClient(SslClientAuthenticationOptions sslClientAuthenticationOptions)
at System.Net.Security.SslStream.AuthenticateAsClient(String targetHost, X509CertificateCollection clientCertificates, SslProtocols enabledSslProtocols, Boolean checkCertificateRevocation)
at Microsoft.Data.SqlClient.SNI.SNITCPHandle.EnableSsl(UInt32 options) in D:\a\_work\1\s\src\Microsoft.Data.SqlClient\netcore\src\Microsoft\Data\SqlClient\SNI\SNITcpHandle.cs:line 615
at ESCMSMauiApp.Views.GetScanData.GetHSHData(Int64 hologramnumber) in C:\Users\stanukula\source\repos\ESCMSMauiApp\ESCMSMauiApp\Views\GetScanData.cs:line 34
at ESCMSMauiApp.Views.HologramScan.GetHologramData() in C:\Users\stanukula\source\repos\ESCMSMauiApp\ESCMSMauiApp\Views\HologramScan.xaml.cs:line 37
at ESCMSMauiApp.Views.HologramScan.Button_Clicked(Object sender, EventArgs e) in C:\Users\stanukula\source\repos\ESCMSMauiApp\ESCMSMauiApp\Views\HologramScan.xaml.cs:line 56
at Microsoft.Maui.Controls.Button.Microsoft.Maui.Controls.Internals.IButtonElement.PropagateUpClicked() in D:\a\_work\1\s\src\Controls\src\Core\Button.cs:line 278
at Microsoft.Maui.Controls.ButtonElement.ElementClicked(VisualElement visualElement, IButtonElement ButtonElementManager) in D:\a\_work\1\s\src\Controls\src\Core\ButtonElement.cs:line 85
at Microsoft.Maui.Controls.Button.SendClicked() in D:\a\_work\1\s\src\Controls\src\Core\Button.cs:line 253
at Microsoft.Maui.Controls.Button.Microsoft.Maui.IButton.Clicked() in D:\a\_work\1\s\src\Controls\src\Core\HandlerImpl\Button\Button.Impl.cs:line 24
at Microsoft.Maui.Handlers.ButtonHandler.OnClick(IButton button, View v) in D:\a\_work\1\s\src\Core\src\Handlers\Button\ButtonHandler.Android.cs:line 153
at Microsoft.Maui.Handlers.ButtonHandler.ButtonClickListener.OnClick(View v) in D:\a\_work\1\s\src\Core\src\Handlers\Button\ButtonHandler.Android.cs:line 174
at Android.Views.View.IOnClickListenerInvoker.n_OnClick_Landroid_view_View_(IntPtr jnienv, IntPtr native__this, IntPtr native_v) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/obj/Release/net7.0/android-33/mcw/Android.Views.View.cs:line 2285
at Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PPL_V(_JniMarshal_PPL_V callback, IntPtr jnienv, IntPtr klazz, IntPtr p0) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs:line 121
ClientConnectionId:7e615876-689c-4f43-b813-b6b9968c9a6b
Error Number:-2146893019,State:0,Class:20} Microsoft.Data.SqlClient.SqlException
Hello
have you tried to connect to this SQL Server using SSMS ? See if you get the same error message. If that´s the case then make sure that firewall in not blocking any SQL ports between client and server
Android and iOS do not support TrustServerCertificate. Neither O/S supports overriding certificate verification.
If android apps are going to access Sqlserver directly rather than webapi proxy, you should buy a trusted certificate for the Sqlserver.
if you want to use self signed certificates, then see the android procedures to load and trust a certificate.
Thanks for your response but...
public static string strConnect = @"Data Source = MSSQLSERVER2019;
Initial Catalog=Ovit_Tecno;
Persist Security Info=True;
User ID = Ovit_Tecno;
Password=xxx;
Connect Timeout = 30;
Encrypt=False;
TrustServerCertificate=True;
Application Intent = ReadWrite;
MultipleActiveResultSets=false;
MultiSubnetFailover=True;
Application Name=Ovit_Software;
Pooling=True;";
this is my connection string and I tried several like this following command by many users
none of them worked