Connecting to Microsoft SQL server from Android App Trust anchor for certification path not found #12018
Unanswered
jpageacsys
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I am trying to port my UWP app for work to Android so our employees can access it on their phone. I was able to get it to build and run, but it is not able to connect to the database.
My app is using Microsoft.Data.SqlClient.
Here is my connection code:
`IOnConnectionFound onConnectionFound = (IOnConnectionFound)arguments[0];
try
{
string connectionString = "Data Source=" + arguments[1] + ";Database=<Redacted;User ID=;Password=MultipleActiveResultSets=true;TrustServerCertificate=True;";
Debug.WriteLine("Trying to connect with string " + connectionString);
using (var connection = new SqlConnection(connectionString))
{
connection.Open();
connection.Close();
}
This works on UWP but on Android I get "javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found."
My android manifest looks like this:
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="AcSYSToolsUno" android:versionCode="1" android:versionName="1.0"> <uses-sdk android:minSdkVersion="21" android:targetSdkVersion="31" /> <uses-permission android:name="android.permission.INTERNET" /> <application android:label="AcSYSToolsUno" android:usesCleartextTraffic="true" android:networkSecurityConfig="@xml/network_security_config"/> </manifest>
And my network security config looks like this:
<?xml version="1.0" encoding="utf-8"?> <network-security-config> <domain-config cleartextTrafficPermitted="true"> <domain includeSubdomains="true"><Redacted></domain> <domain includeSubdomains="true"><Redacted></domain> </domain-config> <base-config cleartextTrafficPermitted="true"/> </network-security-config>
The file is under Resources/xml/network_security_config.xml and Build action is set to AndroidResource.
I'm not sure what else to try. Any ideas?
Thank you!
Beta Was this translation helpful? Give feedback.
All reactions