System.Data.SqlClient.SqlException: 'System.Net.Security.Native assembly:<unknown assembly> type:<unknown type> member:(null)

Ataberk Demir 1 Reputation point
2022-08-24T08:24:11.23+00:00

I coded my data on sql to get xamarine and sqlConnection.Open(); I'm Getting Exception Error in section The error is :

System.Data.SqlClient.SqlException: 'System.Net.Security.Native assembly:<unknown assembly> type:<unknown type> member:(null)
at (wrapper managed-to-native) Interop+NetSecurityNative.ImportPrincipalName(Interop/NetSecurityNative/Status&,string,int,Microsoft.Win32.SafeHandles.SafeGssNameHandle&)
at Microsoft.Win32.SafeHandles.SafeGssNameHandle.CreatePrincipal (System.String name) [0x00000] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corefx/src/Common/src/Microsoft/Win32/SafeHandles/GssSafeHandles.cs:39
at System.Net.Security.SafeDeleteNegoContext..ctor (System.Net.Security.SafeFreeNegoCredentials credential, System.String targetName) [0x0001c] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corefx/src/Common/src/System/Net/Security/Unix/SafeDeleteNegoContext.cs:46
at System.Net.Security.NegotiateStreamPal.EstablishSecurityContext (System.Net.Security.SafeFreeNegoCredentials credential, System.Net.Security.SafeDeleteContext& context, System.String targetName, System.Net.ContextFlagsPal inFlags, System.Net.Security.SecurityBuffer inputBuffer, System.Net.Security.SecurityBuffer outputBuffer, System.Net.ContextFlagsPal& outFlags) [0x0000b] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corefx/src/Common/src/System/Net/Security/NegotiateStreamPal.Unix.cs:166
at System.Net.Security.NegotiateStreamPal.InitializeSecurityContext (System.Net.Security.SafeFreeCredentials credentialsHandle, System.Net.Security.SafeDeleteContext& securityContext, System.String spn, System.Net.ContextFlagsPal requestedContextFlags, System.Net.Security.SecurityBuffer[] inSecurityBufferArray, System.Net.Security.SecurityBuffer outSecurityBuffer, System.Net.ContextFlagsPal& contextFlags) [0x00037] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corefx/src/Common/src/System/Net/Security/NegotiateStreamPal.Unix.cs:240
at System.Data.SqlClient.SNI.SNIProxy.GenSspiClientContext (System.Data.SqlClient.SNI.SspiClientContextStatus sspiClientContextStatus, System.Byte[] receivedBuff, System.Byte[]& sendBuff, System.Byte[] serverName) [0x0006b] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corefx/src/System.Data.SqlClient/src/System/Data/SqlClient/SNI/SNIProxy.cs:113
at System.Data.SqlClient.SNI.TdsParserStateObjectManaged.GenerateSspiClientContext (System.Byte[] receivedBuff, System.UInt32 receivedLength, System.Byte[]& sendBuff, System.UInt32& sendLength, System.Byte[] _sniSpnBuffer) [0x00000] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corefx/src/System.Data.SqlClient/src/System/Data/SqlClient/TdsParserStateObjectManaged.cs:240
at System.Data.SqlClient.TdsParser.SNISSPIData (System.Byte[] receivedBuff, System.UInt32 receivedLength, System.Byte[]& sendBuff, System.UInt32& sendLength) [0x00007] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corefx/src/System.Data.SqlClient/src/System/Data/SqlClient/TdsParser.cs:6488
System.Net.Security.Native assembly:<unknown assembly> type:<unknown type> member:(null)
at (wrapper managed-to-native) Interop+NetSecurityNative.ImportPrincipalName(Interop/NetSecurityNative/Status&,string,int,Microsoft.Win32.SafeHandles.SafeGssNameHandle&)
at Microsoft.Win32.SafeHandles.SafeGssNameHandle.CreatePrincipal (System.String name) [0x00000] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corefx/src/Common/src/Microsoft/Win32/SafeHandles/GssSafeHandles.cs:39
at System.Net.Security.SafeDeleteNegoContext..ctor (System.Net.Security.SafeFreeNegoCredentials credential, System.String targetName) [0x0001c] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corefx/src/Common/src/System/Net/Security/Unix/SafeDeleteNegoContext.cs:46
at System.Net.Security.NegotiateStreamPal.EstablishSecurityContext (System.Net.Security.SafeFreeNegoCredentials credential, System.Net.Security.SafeDeleteContext& context, System.String targetName, System.Net.ContextFlagsPal inFlags, System.Net.Security.SecurityBuffer inputBuffer, System.Net.Security.SecurityBuffer outputBuffer, System.Net.ContextFlagsPal& outFlags) [0x0000b] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corefx/src/Common/src/System/Net/Security/NegotiateStreamPal.Unix.cs:166
at System.Net.Security.NegotiateStreamPal.InitializeSecurityContext (System.Net.Security.SafeFreeCredentials credentialsHandle, System.Net.Security.SafeDeleteContext& securityContext, System.String spn, System.Net.ContextFlagsPal requestedContextFlags, System.Net.Security.SecurityBuffer[] inSecurityBufferArray, System.Net.Security.SecurityBuffer outSecurityBuffer, System.Net.ContextFlagsPal& contextFlags) [0x00037] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corefx/src/Common/src/System/Net/Security/NegotiateStreamPal.Unix.cs:240
at System.Data.SqlClient.SNI.SNIProxy.GenSspiClientContext (System.Data.SqlClient.SNI.SspiClientContextStatus sspiClientContextStatus, System.Byte[] receivedBuff, System.Byte[]& sendBuff, System.Byte[] serverName) [0x0006b] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corefx/src/System.Data.SqlClient/src/System/Data/SqlClient/SNI/SNIProxy.cs:113
at System.Data.SqlClient.SNI.TdsParserStateObjectManaged.GenerateSspiClientContext (System.Byte[] receivedBuff, System.UInt32 receivedLength, System.Byte[]& sendBuff, System.UInt32& sendLength, System.Byte[] _sniSpnBuffer) [0x00000] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corefx/src/System.Data.SqlClient/src/System/Data/SqlClient/TdsParserStateObjectManaged.cs:240
at System.Data.SqlClient.TdsParser.SNISSPIData (System.Byte[] receivedBuff, System.UInt32 receivedLength, System.Byte[]& sendBuff, System.UInt32& sendLength) [0x00007] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corefx/src/System.Data.SqlClient/src/System/Data/SqlClient/TdsParser.cs:6488 '

I have prepared a warning box, connection to sql cannot be established without warning box, my code is like this:

using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Xamarin.Forms;
using Xamarin.Forms.Xaml;

namespace LoginPageSpeedUI.Views
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class ToplantiGoruntule : ContentPage
{

    public class MyTableList  
    {  
        public string Top_Bolum { get; set; }  

        public string Top_Olusturan { get; set; }  

        public string Top_Konusu { get; set; }  
    }  


    SqlConnection sqlConnection;  
    public ToplantiGoruntule()  
    {  
        InitializeComponent();  
          

        string srvrdbname = "MyDbName";  
        string srvrname = "MyDbSource";  
        string serverusarname = "MySrvName";  
        string srvrpassword = "MySrvPass";  
        string sqlconn = $"Data Source={srvrname};Initial Catalog = {srvrdbname};User Id ={serverusarname};Password ={srvrpassword};Trusted_Connection=true";  
        sqlConnection = new SqlConnection(sqlconn);  
    }  


    private async void Button_Clicked(object sender, EventArgs e)  
    {  
        try  
        {  
            sqlConnection.Open();  
            await App.Current.MainPage.DisplayAlert("Alert", "Connection Succed", "Ok");  
            sqlConnection.Close();  
        }  
        catch (Exception ex)  
        {  
            Console.WriteLine(value: ex.Message);  

            throw;  
        }  
    }  
Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,293 questions
SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
12,690 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Ataberk Demir 1 Reputation point
    2022-08-25T05:03:45.633+00:00

    Guys, I solved my problem, First of all I deleted ' Trusted_Connection=true ' at the end of line 21.
    Secondly,
    I got this error on my screen "Encoding 1254 data could not be found. Make sure you have correct international codeset assembly installed and enabled.'" this can be 1252 or any number for you.

    The code mean:

    CodePage BodyName HeaderName WebName Encoding.EncodingName
    shift_jis 932 iso-2022-jp iso-2022-jp shift_jis Japanese (Shift-JIS)
    windows-1250 1250 iso-8859-2 windows-1250 windows-1250 Central European (Windows)
    windows-1251 1251 koi8-r windows-1251 windows-1251 Cyrillic (Windows)
    Windows-1252 1252 iso-8859-1 Windows-1252 Windows-1252 Western European (Windows)
    windows-1253 1253 iso-8859-7 windows-1253 windows-1253 Greek (Windows)
    windows-1254 1254 iso-8859-9 windows-1254 windows-1254 Turkish (Windows)
    csISO2022JP 50221 iso-2022-jp iso-2022-jp csISO2022JP Japanese (JIS-Allow 1 byte Kana)
    iso-2022-kr 50225 iso-2022-kr euc-kr iso-2022-kr Korean (ISO)

    In the the Android project, go to Properties -> Android Options

    Then Linker Options, in the "Additional supported encodings" check "your location".

    And the problem is fixed.