System.Data.SqlClient.SqlException (0x80131904): System.Net.Security.Native error shows up for localhost server but not on an online server?

0

so I've been stuck with this error for a few days now and I can't see to get it to work. I'm trying to get a my unity application (computer platform, not android) to connect to my localhost server (I use Microsoft SQL Server Express) using Microsoft SQL Server Manager. Here's my code:

public void connect(){
      Debug.Log("Connecting to Server");
      string connectionStr = @"Data Source=localhost;Initial Catalog=Test;Integrated Security=True";
      
      SqlConnection dbConnection = new SqlConnection(connectionStr);

      try
      {
          dbConnection.Open();
          Debug.Log("Connected");
      }
      catch(SqlException exception)
      {
          Debug.LogWarning(exception.ToString());
      }

       
      }
  }

This code works when I used an online server but when I changed the connection string for my local server, it gave me the error:

System.Data.SqlClient.SqlException (0x80131904): System.Net.Security.Native

I believe it is either from the server itself or from the connection string. I tried to look this up online but they usually have to do with Xamarian/Android errors, or I've already tried their suggestions, and I'm a noob with databases. Can someone help me with this or at least tell me why this error appears?

*I have TCP/IP Enabled and I am currently using Windows

Edit: Full error:

System.Data.SqlClient.SqlException (0x80131904): System.Net.Security.Native
  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) [0x0000e] in <290425a50ff84a639f8c060e2d4530f6>:0 
  at System.Net.Security.SafeDeleteNegoContext..ctor (System.Net.Security.SafeFreeNegoCredentials credential, System.String targetName) [0x0001c] in <290425a50ff84a639f8c060e2d4530f6>:0 
  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 <290425a50ff84a639f8c060e2d4530f6>:0 
  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) [0x0002a] in <290425a50ff84a639f8c060e2d4530f6>:0 
  at System.Data.SqlClient.SNI.SNIProxy.GenSspiClientContext (System.Data.SqlClient.SNI.SspiClientContextStatus sspiClientContextStatus, System.Byte[] receivedBuff, System.Byte[]& sendBuff, System.Byte[] serverName) [0x0006b] in <290425a50ff84a639f8c060e2d4530f6>:0 
  at System.Data.SqlClient.SNI.TdsParserStateObjectManaged.GenerateSspiClientContext (System.Byte[] receivedBuff, System.UInt32 receivedLength, System.Byte[]& sendBuff, System.UInt32& sendLength, System.Byte[] _sniSpnBuffer) [0x00000] in <290425a50ff84a639f8c060e2d4530f6>:0 
  at System.Data.SqlClient.TdsParser.SNISSPIData (System.Byte[] receivedBuff, System.UInt32 receivedLength, System.Byte[]& sendBuff, System.UInt32& sendLength) [0x00007] in <290425a50ff84a639f8c060e2d4530f6>:0 
System.Net.Security.Native
  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) [0x0000e] in <290425a50ff84a639f8c060e2d4530f6>:0 
  at System.Net.Security.SafeDeleteNegoContext..ctor (System.Net.Security.SafeFreeNegoCredentials credential, System.String targetName) [0x0001c] in <290425a50ff84a639f8c060e2d4530f6>:0 
  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 <290425a50ff84a639f8c060e2d4530f6>:0 
  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) [0x0002a] in <290425a50ff84a639f8c060e2d4530f6>:0 
  at System.Data.SqlClient.SNI.SNIProxy.GenSspiClientContext (System.Data.SqlClient.SNI.SspiClientContextStatus sspiClientContextStatus, System.Byte[] receivedBuff, System.Byte[]& sendBuff, System.Byte[] serverName) [0x0006b] in <290425a50ff84a639f8c060e2d4530f6>:0 
  at System.Data.SqlClient.SNI.TdsParserStateObjectManaged.GenerateSspiClientContext (System.Byte[] receivedBuff, System.UInt32 receivedLength, System.Byte[]& sendBuff, System.UInt32& sendLength, System.Byte[] _sniSpnBuffer) [0x00000] in <290425a50ff84a639f8c060e2d4530f6>:0 
  at System.Data.SqlClient.TdsParser.SNISSPIData (System.Byte[] receivedBuff, System.UInt32 receivedLength, System.Byte[]& sendBuff, System.UInt32& sendLength) [0x00007] in <290425a50ff84a639f8c060e2d4530f6>:0 
  at System.Data.SqlClient.SqlInternalConnectionTds..ctor (System.Data.ProviderBase.DbConnectionPoolIdentity identity, System.Data.SqlClient.SqlConnectionString connectionOptions, System.Object at System.Data.SqlClient.SqlInternalConnectionTds..ctor (System.Data.ProviderBase.DbConnectionPoolIdentity identity, System.Data.SqlClient.SqlConnectionString connectionOptions, System.Object providerInfo, System.Boolean redirectedUserInstance, System.Data.SqlClient.SqlConnectionString userConnectionOptions, System.Data.SqlClient.SessionData reconnectSessionData, System.Boolean applyTransientFaultHandling) [0x00156] in <290425a50ff84a639f8c060e2d4530f6>:0 
  at System.Data.SqlClient.SqlConnectionFactory.CreateConnection (System.Data.Common.DbConnectionOptions options, System.Data.Common.DbConnectionPoolKey poolKey, System.Object poolGroupProviderInfo, System.Data.ProviderBase.DbConnectionPool pool, System.Data.Common.DbConnection owningConnection, System.Data.Common.DbConnectionOptions userOptions) [0x0012a] in <290425a50ff84a639f8c060e2d4530f6>:0 
  at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection (System.Data.ProviderBase.DbConnectionPool pool, System.Data.Common.DbConnection owningObject, System.Data.Common.DbConnectionOptions options, System.Data.Common.DbConnectionPoolKey poolKey, System.Data.Common.DbConnectionOptions userOptions) [0x0000c] in <290425a50ff84a639f8c060e2d4530f6>:0 
  at System.Data.ProviderBase.DbConnectionPool.CreateObject (System.Data.Common.DbConnection owningObject, System.Data.Common.DbConnectionOptions userOptions, System.Data.ProviderBase.DbConnectionInternal oldConnection) [0x00184] in <290425a50ff84a639f8c060e2d4530f6>:0 
  at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest (System.Data.Common.DbConnection owningObject, System.Data.Common.DbConnectionOptions userOptions, System.Data.ProviderBase.DbConnectionInternal oldConnection) [0x00040] in <290425a50ff84a639f8c060e2d4530f6>:0 
  at System.Data.ProviderBase.DbConnectionPool.TryGetConnection (System.Data.Common.DbConnection owningObject, System.UInt32 waitForMultipleObjectsTimeout, System.Boolean allowCreate, System.Boolean onlyOneCheckConnection, System.Data.Common.DbConnectionOptions userOptions, System.Data.ProviderBase.DbConnectionInternal& connection) [0x000a4] in <290425a50ff84a639f8c060e2d4530f6>:0 
  at System.Data.ProviderBase.DbConnectionPool.TryGetConnection (System.Data.Common.DbConnection owningObject, System.Threading.Tasks.TaskCompletionSource`1[TResult] retry, System.Data.Common.DbConnectionOptions userOptions, System.Data.ProviderBase.DbConnectionInternal& connection) [0x00026] in <290425a50ff84a639f8c060e2d4530f6>:0 
  at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection (System.Data.Common.DbConnection owningConnection, System.Threading.Tasks.TaskCompletionSource`1[TResult] retry, System.Data.Common.DbConnectionOptions userOptions, System.Data.ProviderBase.DbConnectionInternal oldConnection, System.Data.ProviderBase.DbConnectionInternal& connection) [0x0021d] in <290425a50ff84a639f8c060e2d4530f6>:0 
  at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal (System.Data.Common.DbConnection outerConnection, System.Data.ProviderBase.DbConnectionFactory connectionFactory, System.Threading.Tasks.TaskCompletionSource`1[TResult] retry, System.Data.Common.DbConnectionOptions userOptions) [0x00036] in <290425a50ff84a639f8c060e2d4530f6>:0 
  at System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection (System.Data.Common.DbConnection outerConnection, System.Data.ProviderBase.DbConnectionFactory connectionFactory, System.Threading.Tasks.TaskCompletionSource`1[TResult] retry, System.Data.Common.DbConnectionOptions userOptions) [0x00000] in <290425a50ff84a639f8c060e2d4530f6>:0 
  at System.Data.SqlClient.SqlConnection.TryOpen (System.Threading.Tasks.TaskCompletionSource`1[TResult] retry) [0x0005d] in <290425a50ff84a639f8c060e2d4530f6>:0 
  at System.Data.SqlClient.SqlConnection.Open () [0x0003b] in <290425a50ff84a639f8c060e2d4530f6>:0 
  at DbManager.connect () 
c#
sql-server
unity3d
server
ssms
asked on Stack Overflow Jan 8, 2021 by Tess • edited Jan 8, 2021 by Tess

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0