Search Unity

Help Wanted UNITY HAVING CONNECTION ISSUES WHEN I TRY TO CONNECT TO SQL SERVER WINDOWS AUTHENTICATION/SQL SERVER

Discussion in 'Multiplayer' started by youssuf212, May 20, 2020.

  1. youssuf212

    youssuf212

    Joined:
    Mar 27, 2020
    Posts:
    2
    Hello there,
    I have a problem connecting unity with Sql server (c#)
    i have tried to use different methods to connect but still errors , but different errors though
    that is my source code :

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using System.Text;
    4. using System.Threading.Tasks;
    5. using System.Data;
    6. using System.Data.SqlClient;
    7.  
    8.  
    9.  
    10. public class GameManager : MonoBehaviour
    11. {
    12.     // Start is called before the first frame update
    13.     void Start()
    14.     {
    15.         SimpleQuery("SELECT TOP 1000 [FirstName] FROM Person.Person ");
    16.     }
    17.  
    18.     private string _conString = @"Data Source =(local)\MSSQLSERVER2012;
    19.     Initial Catalog = AdventureWorks2012;
    20.     Integrated Security=True";
    21.     public string SimpleQuery(string _query)
    22.     {
    23.         using (SqlConnection dbCon = new SqlConnection(_conString))
    24.         {
    25.             SqlCommand cmd = new SqlCommand(_query, dbCon);
    26.             try
    27.             {
    28.                 dbCon.Open();
    29.                 string _returnQuery = (string)cmd.ExecuteScalar();
    30.                 return _returnQuery;
    31.             }
    32.             catch (SqlException _exception)
    33.             {
    34.                 Debug.LogWarning(_exception.ToString());
    35.                 return null;
    36.             }
    37.         }
    38.     }
    39.     // Update is called once per frame
    40.     void Update()
    41.     {
    42.        
    43.     }
    44.  
    45.  
    46. }
    47.  

    i made sure system.data is in my asset folder
    i can connect easily when i use sql server management studio
    Thanks in advance ;;
    the error reads:
    SocketException: An existing connection was forcibly closed by the remote host.

    System.Net.Sockets.SocketAsyncResult.CheckIfThrowDelayedException () (at <ae22a4e8f83c41d69684ae7f557133d9>:0)
    System.Net.Sockets.Socket.EndReceiveFrom (System.IAsyncResult asyncResult, System.Net.EndPoint& endPoint) (at <ae22a4e8f83c41d69684ae7f557133d9>:0)
    System.Net.Sockets.UdpClient.EndReceive (System.IAsyncResult asyncResult, System.Net.IPEndPoint& remoteEP) (at <ae22a4e8f83c41d69684ae7f557133d9>:0)
    System.Net.Sockets.UdpClient.<ReceiveAsync>b__64_1 (System.IAsyncResult ar) (at <ae22a4e8f83c41d69684ae7f557133d9>:0)
    System.Threading.Tasks.TaskFactory`1[TResult].FromAsyncCoreLogic (System.IAsyncResult iar, System.Func`2[T,TResult] endFunction, System.Action`1[T] endAction, System.Threading.Tasks.Task`1[TResult] promise, System.Boolean requiresSynchronization) (at <437ba245d8404784b9fbab9b439ac908>:0)
    Rethrow as AggregateException: One or more errors occurred.
    System.Threading.Tasks.Task.ThrowIfExceptional (System.Boolean includeTaskCanceledExceptions) (at <437ba245d8404784b9fbab9b439ac908>:0)
    System.Threading.Tasks.Task.Wait (System.Int32 millisecondsTimeout, System.Threading.CancellationToken cancellationToken) (at <437ba245d8404784b9fbab9b439ac908>:0)
    System.Threading.Tasks.Task.Wait (System.Int32 millisecondsTimeout) (at <437ba245d8404784b9fbab9b439ac908>:0)
    System.Data.SqlClient.SNI.SSRP.SendUDPRequest (System.String browserHostname, System.Int32 port, System.Byte[] requestPacket) (at <290425a50ff84a639f8c060e2d4530f6>:0)
    System.Data.SqlClient.SNI.SSRP.GetPortByInstanceName (System.String browserHostName, System.String instanceName) (at <290425a50ff84a639f8c060e2d4530f6>:0)
    System.Data.SqlClient.SNI.SNIProxy.CreateTcpHandle (System.Data.SqlClient.SNI.DataSource details, System.Int64 timerExpire, System.Object callbackObject, System.Boolean parallel) (at <290425a50ff84a639f8c060e2d4530f6>:0)
    System.Data.SqlClient.SNI.SNIProxy.CreateConnectionHandle (System.Object callbackObject, System.String fullServerName, System.Boolean ignoreSniOpenTimeout, System.Int64 timerExpire, System.Byte[]& instanceName, System.Byte[]& spnBuffer, System.Boolean flushCache, System.Boolean async, System.Boolean parallel, System.Boolean isIntegratedSecurity) (at <290425a50ff84a639f8c060e2d4530f6>:0)
    System.Data.SqlClient.SNI.TdsParserStateObjectManaged.CreatePhysicalSNIHandle (System.String serverName, System.Boolean ignoreSniOpenTimeout, System.Int64 timerExpire, System.Byte[]& instanceName, System.Byte[]& spnBuffer, System.Boolean flushCache, System.Boolean async, System.Boolean parallel, System.Boolean isIntegratedSecurity) (at <290425a50ff84a639f8c060e2d4530f6>:0)
    System.Data.SqlClient.TdsParser.Connect (System.Data.SqlClient.ServerInfo serverInfo, System.Data.SqlClient.SqlInternalConnectionTds connHandler, System.Boolean ignoreSniOpenTimeout, System.Int64 timerExpire, System.Boolean encrypt, System.Boolean trustServerCert, System.Boolean integratedSecurity, System.Boolean withFailover) (at <290425a50ff84a639f8c060e2d4530f6>:0)
    System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin (System.Data.SqlClient.ServerInfo serverInfo, System.Boolean ignoreSniOpenTimeout, System.Data.ProviderBase.TimeoutTimer timeout, System.Boolean withFailover) (at <290425a50ff84a639f8c060e2d4530f6>:0)
    System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover (System.Data.SqlClient.ServerInfo serverInfo, System.Boolean redirectedUserInstance, System.Data.SqlClient.SqlConnectionString connectionOptions, System.Data.ProviderBase.TimeoutTimer timeout) (at <290425a50ff84a639f8c060e2d4530f6>:0)
    System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist (System.Data.ProviderBase.TimeoutTimer timeout, System.Data.SqlClient.SqlConnectionString connectionOptions, System.Boolean redirectedUserInstance) (at <290425a50ff84a639f8c060e2d4530f6>:0)
    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) (at <290425a50ff84a639f8c060e2d4530f6>:0)
    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) (at <290425a50ff84a639f8c060e2d4530f6>:0)
    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) (at <290425a50ff84a639f8c060e2d4530f6>:0)
    System.Data.ProviderBase.DbConnectionPool.CreateObject (System.Data.Common.DbConnection owningObject, System.Data.Common.DbConnectionOptions userOptions, System.Data.ProviderBase.DbConnectionInternal oldConnection) (at <290425a50ff84a639f8c060e2d4530f6>:0)
    System.Data.ProviderBase.DbConnectionPool.UserCreateRequest (System.Data.Common.DbConnection owningObject, System.Data.Common.DbConnectionOptions userOptions, System.Data.ProviderBase.DbConnectionInternal oldConnection) (at <290425a50ff84a639f8c060e2d4530f6>:0)
    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) (at <290425a50ff84a639f8c060e2d4530f6>:0)
    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) (at <290425a50ff84a639f8c060e2d4530f6>:0)
    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) (at <290425a50ff84a639f8c060e2d4530f6>:0)
    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) (at <290425a50ff84a639f8c060e2d4530f6>:0)
    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) (at <290425a50ff84a639f8c060e2d4530f6>:0)
    System.Data.SqlClient.SqlConnection.TryOpen (System.Threading.Tasks.TaskCompletionSource`1[TResult] retry) (at <290425a50ff84a639f8c060e2d4530f6>:0)
    System.Data.SqlClient.SqlConnection.Open () (at <290425a50ff84a639f8c060e2d4530f6>:0)
    GameManager.SimpleQuery (System.String _query) (at Assets/Scripts/GameManager.cs:30)
    GameManager.Start () (at Assets/Scripts/GameManager.cs:17)
     
unityunity