[Mono-list] Database Connection issue with Mono 1.2.5 and SQL Server 2005

jashan david at daten-raum.de
Sun Mar 1 16:37:34 EST 2009


Hi there,


since I'm using Mono embedded in Unity (the game-engine), I still have to
work with Mono 1.2.5 which is "kind of old". Anyways, I'm hoping there's a
solution to my problem:


I have a game server which connects to a SQL Server 2005 with
System.Data.SqlClient.SqlConnection. Most of the time, everything is working
perfectly - usually for many days. However, every once in a while, the
connection appears to break - and from that moment, any database command
results in the exception included below. This only stops when I shutdown the
game-server and restart it.


I'm assuming that there's some sort of connection pool and for some reason
these connections "break" and then aren't re-opened properly. If so, is
there a way to somehow reset those connections (in 1.2.5)?


I do lose a few packets when doing pings from the game-server to the
database server which might explain why the connections break (it's much
less than 1% packet loss but still some packets get lost).


So here's the exception and code I'm using:


System.IO.IOException: Write failure --->
System.Net.Sockets.SocketException: Connection reset by peer
  at System.Net.Sockets.Socket.Send (System.Byte[] buf, Int32 offset, Int32
size, SocketFlags flags) [0x00000] 
  at System.Net.Sockets.NetworkStream.Write (System.Byte[] buffer, Int32
offset, Int32 size) [0x00000] --- End of inner exception stack trace ---

  at System.Net.Sockets.NetworkStream.Write (System.Byte[] buffer, Int32
offset, Int32 size) [0x00000] 
  at Mono.Data.Tds.Protocol.TdsComm.SendPhysicalPacket (Boolean
isLastSegment) [0x00000] 
  at Mono.Data.Tds.Protocol.TdsComm.SendPacket () [0x00000] 
  at Mono.Data.Tds.Protocol.Tds70.ExecRPC (System.String rpcName,
Mono.Data.Tds.TdsMetaParameterCollection parameters, Int32 timeout, Boolean
wantResults) [0x00000] 
  at Mono.Data.Tds.Protocol.Tds70.ExecProc (System.String commandText,
Mono.Data.Tds.TdsMetaParameterCollection parameters, Int32 timeout, Boolean
wantResults) [0x00000] 
  at System.Data.SqlClient.SqlCommand.Execute (CommandBehavior behavior,
Boolean wantResults) [0x00000] 
  at System.Data.SqlClient.SqlCommand.ExecuteNonQuery () [0x00000] 
  at JCsDBAccess.ExecuteNonQuerySynchronously (System.String procedureName,
System.Collections.Generic.List`1 parameters) [0x00000] 


The code I'm using to connect to the database is:

    public int ExecuteNonQuerySynchronously(string procedureName, List
parameters) {
        int result = 0;
        try {
            using (IDbConnection dbcon = new
SqlConnection(connectionString)) {
                using (IDbCommand dbcmd = dbcon.CreateCommand()) {
                    dbcmd.CommandType = CommandType.StoredProcedure;
                    dbcmd.CommandText = procedureName;
                    foreach (SqlParameter parameter in parameters) {
                        dbcmd.Parameters.Add(parameter);
                    }
                    dbcon.Open();
                    result = dbcmd.ExecuteNonQuery();
                    dbcon.Close();
                    log.DebugFormat("... {0}.ExecutingNonQuery executed.",
procedureName);
                }
            }
        } catch (Exception exc) {
            LogException(procedureName, parameters, exc);
        }
        return result;
    }


Sunny regards,

Jashan

-- 
View this message in context: http://www.nabble.com/Database-Connection-issue-with-Mono-1.2.5-and-SQL-Server-2005-tp22278355p22278355.html
Sent from the Mono - General mailing list archive at Nabble.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-list/attachments/20090301/cf83c522/attachment.html 


More information about the Mono-list mailing list