SQL ServerConnection from Unity

0

I am trying to connect my Unity instance to an SQL Client. I switched to Net Framework 4.x and have written the following code:

        serverConfig conf = JsonUtility.FromJson<serverConfig>(File.ReadAllText(@"Assets/Scripts/config.json"));
        

        string connString = string.Format("Data Source={0},{1};Initial Catalog={2};User ID={3};Password={4}",
            conf.address, conf.port, conf.database, conf.username, conf.password);
            
            //debug
            print(connString);

            SqlConnection cnn = new SqlConnection(connString);

            try {
                cnn.Open();
                print("Connection open");
                cnn.Close();
            }
            catch (Exception e) {
                print("Could not open connection :" + e);
            }

Where the Connection String is:

Server=xxxxx.xxxxxx.us-east-2.rds.amazonaws.com,5432;Initial Catalog=GameData;User ID=user;Password=password

At runtime, it throws the following error:

Could not open connection :System.Data.SqlClient.SqlException (0x80131904): Snix_PreLogin (provider: SNI_PN7, error: 0 - mono-io-layer-error (0))
Snix_PreLogin (provider: SNI_PN7, error: 0 - mono-io-layer-error (0))
  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 SQLCommunicator.Start () [0x00059] in /xxxxxxxx/Assets/Scripts/SQLCommunicator.cs:35 
ClientConnectionId:9f9e5b47-c097-4e03-a6ed-a77b13b9fa05
UnityEngine.MonoBehaviour:print (object)
SQLCommunicator:Start () (at Assets/Scripts/SQLCommunicator.cs:40)

I am able to connect to the database just fine using pgadmin but my Unity instance is unable to make a connection and I do not know how to fix the mono-io-layer-error (0)

c#
database
unity3d
sqlclient
asked on Stack Overflow Apr 12, 2021 by anguishedsix50

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0