简体   繁体   中英

C# Socket Server - Flash Clients - Database Access & Perfomance

I have constructed ac# socket server which is going to be the server for a flash based game. So far, so good.

I want to use a MySQL server for storing data which is going to be used for storing user items, current configuration etc. Is it advised to create an open persistent connection to my mysql server to keep firing small updates from my flash clients, or should I rely on keeping my server dealing with the in & out and communication. They rely on a language like PHP for performing the database updates?

Would there be any performance gains either way?

Greetings earthling. I have to regretfully inform you that your question is a bit vague and you have therefore not gotten any answers.

As for your database question (which is a bit of hidden in all that text ;)): No. You should not keep the connection open. All modern ADO.NET drivers are using connection pooling internally. This means that the connection to the database will be left open even if you call MysqlConnection.Close() . So leave it up to the driver to handle that.

A common practice is to use using on everything that implements IDisposable . It makes sure that the object is clean up properly even if the code throws an exception.

using (var connection = new MySqlConnection(myConnectionString)
{
    using (var cmd = connection.CreateCommand())
    {
        cmd.CommandText = "Insert into yourtable";
        cmd.ExecuteNonQuery();
    }
}

Create a new more specific question if you had any more questions in your text.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM