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

Connecting to SqlServer errors #10111

Closed
mamqua opened this issue Sep 14, 2022 · 18 comments
Closed

Connecting to SqlServer errors #10111

mamqua opened this issue Sep 14, 2022 · 18 comments
Labels
platform/android 🤖 s/needs-attention Issue has more information and needs another look t/bug Something isn't working

Comments

@mamqua
Copy link

mamqua commented Sep 14, 2022

Description

I tried with a lot of different solutions but nothing seems working: the android emulator can't connect sqlserver.
Is there some bug that should be fixed? i'm loosing time?

Steps to Reproduce

string str = StringaConnessione(DB, Server);
                string qs = "SELECT * FROM dbo.Agenti;";
                using (SqlConnection connection = new SqlConnection(
                           str))
                {
                try
                {
                    connection.Open();

                }
                catch (Exception rt)
                {
                    string ff;
                    ff = rt.Message;
                }


                    SqlCommand command = new SqlCommand(qs, connection);
                
                    
                    command.ExecuteNonQuery();
                }

Link to public reproduction project repository

no public repository

Version with bug

6.0.486 (current)

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

Android from 29

Did you find any workaround?

no

Relevant log output

No response

@mamqua mamqua added the t/bug Something isn't working label Sep 14, 2022
@drasticactions
Copy link
Contributor

  1. I doubt this is a MAUI (The UI Framework) issue, but another issue with your code. If you try to do the same thing in a net6 android app (dotnet new android) does it connect?
  2. You probably don't want to connect directly to a database through your app.

@PureWeen PureWeen added s/needs-info Issue needs more info from the author s/needs-repro Attach a solution or code which reproduces the issue labels Sep 14, 2022
@ghost
Copy link

ghost commented Sep 14, 2022

Hi @mamqua. We have added the "s/needs-repro" label to this issue, which indicates that we require steps and sample code to reproduce the issue before we can take further action. Please try to create a minimal sample project/solution or code samples which reproduce the issue, ideally as a GitHub repo that we can clone. See more details about creating repros here: https://github.com/dotnet/maui/blob/main/.github/repro.md

This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

@ghost
Copy link

ghost commented Sep 14, 2022

Hi @mamqua. We have added the "s/needs-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

@janseris
Copy link

janseris commented Sep 15, 2022

It's the used MAUI Android SSL implementation issue on some Androids.

@ghost ghost added s/needs-attention Issue has more information and needs another look and removed s/needs-info Issue needs more info from the author s/needs-repro Attach a solution or code which reproduces the issue labels Sep 15, 2022
@mamqua
Copy link
Author

mamqua commented Sep 15, 2022

  1. I doubt this is a MAUI (The UI Framework) issue, but another issue with your code. If you try to do the same thing in a net6 android app (dotnet new android) does it connect?
  2. You probably don't want to connect directly to a database through your app.
  1. The code is really simple , it works if i use windowsmachine emulator but not with all android's emulators or android device conneccted
  2. i want connect directly to the database

@janseris
Copy link

Could you post what error do you receive and on which Android version?

@mamqua
Copy link
Author

mamqua commented Sep 15, 2022

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)

since android 10 version in MAUI

TLS1.2 is enabled of course

@janseris
Copy link

@mamqua are you using SQL Server Express 2019?

@mamqua
Copy link
Author

mamqua commented Sep 15, 2022

@mamqua are you using SQL Server Express 2019?

no but i tryed with all other version. sqlserver 2016 in the our network, sqlserver 2019 developr locally in my machine

@janseris
Copy link

@mamqua
Copy link
Author

mamqua commented Sep 15, 2022

Hi @mamqua. We have added the "s/needs-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

https://github.com/mamqua/TestMauiSqlServerConnection

@mamqua
Copy link
Author

mamqua commented Sep 15, 2022

dotnet/SqlClient#1656 dotnet/SqlClient#1662

still tryed all but not working. atm i found a video with new tips i'll try follow that way

@janseris
Copy link

@mamqua could you share the video? I am interested as well to see any help with this issue

@mamqua
Copy link
Author

mamqua commented Sep 15, 2022

@mamqua could you share the video? I am interested as well to see any help with this issue

Now we are working at sqlserver configuration and updates but when we will finish that job i'll make a video. thx

@jfversluis
Copy link
Member

As all linked issues show, I don't believe this is something that originates in .NET MAUI unfortunately. Keep tracking the linked issues to get this resolved. Another workaround, as already mentioned, is to not connect to a DB directly and place an API in-between.

@jfversluis jfversluis closed this as not planned Won't fix, can't repro, duplicate, stale Oct 7, 2022
@janseris
Copy link

janseris commented Oct 8, 2022

@jfversluis It's an issue with Android TLS/SSL provider which MAUI uses. The errors don't happen on other platforms than MAUI. This means that it is a MAUI problem (edit: Android in .NET problem, right.). Or a leftover Xamarin problem.
How do you suggest that these issues should be solved when it doesn't happen for other platforms and it is evident that it's .NET Android problem if you check the exception trace that the error is from Android TLS/SSL provider?
It's the same issue over and over: dotnet/SqlClient#1656

Issue moved from https://github.com/dotnet/maui/issues/6859
Issue moved from https://github.com/xamarin/xamarin-android/issues/6990

But noone in SqlClient can fix .NET Android SSL providers.

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

@drasticactions
Copy link
Contributor

"It's an issue with Android TLS/SSL provider which MAUI uses"

MAUI (This Repo) is a UI Framework for cross platform applications. MAUI (The UI Framework, this Repo) is built on top of MAUI (Or more specifically, .NET For Android), the .NET binding for Android.

Your issue is not something that can be fixed in this repo.

This issue should probably go to https://github.com/xamarin/xamarin-android or maybe https://github.com/dotnet/runtime, although it could be a root Android issue (Hence why it only happens on Android, and no other platform that MAUI (The UI Framework) supports, since those run on... other platforms...

@jonathanpeppers Would you have any ideas of where this should go? Should it stay here?

@janseris
Copy link

janseris commented Oct 8, 2022

Thank you.

although it could be a root Android issue (Hence why it only happens on Android, and no other platform that MAUI (The UI Framework) supports, since those run on... other platforms...

Just to add a bit of additional info here, we have old Android applications (running on Android 8.1 and lower) communicating with the same SQL Server with TLS (TLS is always used in TDS (SQL Server communication protocol on port 1433) for login even when Encrypt=false in connection string (which means that the data after SQL Server login process finishes are/aren't encrypted). These apps connect fine. I believe it was as old as Android 4.4

@ghost ghost locked as resolved and limited conversation to collaborators Nov 7, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
platform/android 🤖 s/needs-attention Issue has more information and needs another look t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants