Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQL Server pre-login handshake failed Android 5,6,8.1 #6859

Closed
janseris opened this issue May 5, 2022 · 7 comments
Closed

SQL Server pre-login handshake failed Android 5,6,8.1 #6859

janseris opened this issue May 5, 2022 · 7 comments
Labels
external partner/android Issues for the Android SDK partner Issue or Request from a partner team platform/android 🤖 t/bug Something isn't working

Comments

@janseris
Copy link

janseris commented May 5, 2022

Description

SQL Server - the connection was established but pre-login handshake failed when calling database via Entity Framework

**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)'

What does not help:

  • Encrypt=false in connection string
  • Encrypt=true in connection string
  • Encrypt=false;TrustServerCertificate=true; in connection string

The same works without any issue on Android 9 and up (both emulator and real device).
Tested: works on Android 9 for all TLS settings: Native TLS 1.2+ and Managed TLS 1.0 and also for "no option".

image

The issue is in Debug (and thus probably also in Release) configuration.

Output for Android 5 (API 21):
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)'

Output for Android 8, for all TLS configuration options: Native TLS 1.2+ and Managed TLS 1.0 and also for "no option".

[System.err] java.lang.IllegalStateException: Handshake has already been started
[System.err] 	at com.android.org.conscrypt.OpenSSLEngineImpl.beginHandshakeInternal(OpenSSLEngineImpl.java:335)
[System.err] 	at com.android.org.conscrypt.OpenSSLEngineImpl.beginHandshake(OpenSSLEngineImpl.java:325)
[System.err] 	at crc640ec207abc449b2ca.ShellSectionRenderer.n_onCreateView(Native Method)
[System.err] 	at crc640ec207abc449b2ca.ShellSectionRenderer.onCreateView(ShellSectionRenderer.java:42)
[System.err] 	at androidx.fragment.app.Fragment.performCreateView(Fragment.java:2995)
[System.err] 	at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:523)
[System.err] 	at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:261)
[System.err] 	at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:1840)
[System.err] 	at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:1764)
[System.err] 	at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:1701)
[System.err] 	at androidx.fragment.app.FragmentManager.dispatchStateChange(FragmentManager.java:2849)
[System.err] 	at androidx.fragment.app.FragmentManager.dispatchViewCreated(FragmentManager.java:2777)
[System.err] 	at androidx.fragment.app.Fragment.performViewCreated(Fragment.java:3020)
[System.err] 	at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:551)
[System.err] 	at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:261)
[System.err] 	at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:1840)
[System.err] 	at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:1764)
[System.err] 	at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:1701)
[System.err] 	at androidx.fragment.app.FragmentManager.dispatchStateChange(FragmentManager.java:2849)
[System.err] 	at androidx.fragment.app.FragmentManager.dispatchActivityCreated(FragmentManager.java:2784)
[System.err] 	at androidx.fragment.app.FragmentController.dispatchActivityCreated(FragmentController.java:262)
[System.err] 	at androidx.fragment.app.FragmentActivity.onStart(FragmentActivity.java:478)
[System.err] 	at androidx.appcompat.app.AppCompatActivity.onStart(AppCompatActivity.java:246)
[System.err] 	at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1333)
[System.err] 	at android.app.Activity.performStart(Activity.java:6992)
[System.err] 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2780)
[System.err] 	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
[System.err] 	at android.app.ActivityThread.-wrap11(Unknown Source:0)
[System.err] 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
[System.err] 	at android.os.Handler.dispatchMessage(Handler.java:105)
[System.err] 	at android.os.Looper.loop(Looper.java:164)
[System.err] 	at android.app.ActivityThread.main(ActivityThread.java:6541)
[System.err] 	at java.lang.reflect.Method.invoke(Native Method)
[System.err] 	at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
[System.err] 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
**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)'

Similar issues:
#3522

Steps to Reproduce

call database in a MAUI app with Android 8.1 or lower

Version with bug

Release Candidate 2 (current)

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

Android 8.1 and below

Did you find any workaround?

no

Relevant log output

No response

@janseris janseris added s/needs-verification Indicates that this issue needs initial verification before further triage will happen t/bug Something isn't working labels May 5, 2022
@Redth Redth added platform/android 🤖 partner/android Issues for the Android SDK labels May 5, 2022
@Redth Redth added this to the 6.0.300-servicing milestone May 5, 2022
@Redth
Copy link
Member

Redth commented May 5, 2022

Generally best practice would be to not connect directly to a database from a mobile application where you'll risk the server credentials being discoverable.

Aside from that, @jonpryor any ideas?

@drasticactions
Copy link
Contributor

This won't be MAUI specific in any case, right? Like with that other issue linked, this stack is entirely Android and that would point to it being a net6-android issue (or at least something you need to change at a project level).

@Eilon
Copy link
Member

Eilon commented May 5, 2022

Should we move this to the xamarin-android repo?

@Redth
Copy link
Member

Redth commented May 5, 2022

I'll let @jonpryor handle moving and closing as necessary. Unfortunately we can't move issues across orgs with GitHub, it has to be 'manually' moved.

@Eilon
Copy link
Member

Eilon commented May 5, 2022

I have magic tools that can do this (it just automates the manual steps using APIs).

@jfversluis jfversluis removed the s/needs-verification Indicates that this issue needs initial verification before further triage will happen label May 6, 2022
@Eilon
Copy link
Member

Eilon commented May 9, 2022

This issue was moved to dotnet/android#6990

@Eilon Eilon removed this from the 6.0.300-servicing milestone May 9, 2022
@Eilon Eilon closed this as completed May 9, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Jun 8, 2022
@dotnet dotnet unlocked this conversation Jun 21, 2022
@jonathanpeppers
Copy link
Member

It looks like I don't have permission to move this to https://github.com/dotnet/SqlClient. Will check on another option.

@dotnet dotnet locked as resolved and limited conversation to collaborators Jun 21, 2022
@samhouts samhouts added partner Issue or Request from a partner team external labels May 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
external partner/android Issues for the Android SDK partner Issue or Request from a partner team platform/android 🤖 t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

7 participants