Han unstoppable Han unstoppable -4 years ago 133
C# Question

.NET with MySqlConnection and Connection Pool

I'm beginner working with .NET and Mysql Connection.

To avoid misunderstanding about

Connection pool
for .NET I want to ask some my question.

Here is simple my code

class Program
{
static void Main(string[] args)
{
string connectionSetting = "Data Source=127.0.0.1;Database=my_table; User Id=root;Password=root" + ";charset=euckr";

MySqlConnection con = new MySqlConnection(connectionSetting);

con.Open();

MySqlCommand command = new MySqlCommand("insert into log(strLog) values('log1')", con);

command.ExecuteNonQuery();

con.Close();
}
}


I've been trying to how to make connection instance for mysql-server, the answer was singleton, But I found many post in StackOverflow and Some answers say Don't share
MySql Connection
instance and that's all i have to do.

My question is "Who is controlling Connection Pool?"

In the above code, there is no code that relates to controlling the connection pool such as the GetPool, PutPool and so on calls. So I thought database connection pool is controlled in mysql-server side and there is not any other jobs on the .NET side. Is my understanding correct?

If my thought is right, I'll use the following codes.

class dbcp
{
public const string m_ConnectionString = "Data Source=127.0.0.1;Database=my_table; User Id=root;Password=root" + ";charset=euckr";

public MySqlConnection connection;

public dbcp() { }

public void QueryLog(string log)
{
connection = new MySqlConnection(m_ConnectionString);
connection.Open();

string strSQL = "insert into log(strLog) values('log1')";
MySqlCommand cmd = new MySqlCommand(strSQL, connection);
cmd.ExecuteNonQuery();

connection.Close();
}
}

class SomeClassA
{
public dbcp dbHandler;
}

class SomeClassB
{
public dbcp dbHandler;
}

class Program
{
static void Main(string[] args)
{
string connectionSetting = "Data Source=127.0.0.1;Database=gw_ocpp_server; User Id=root;Password=root" + ";charset=euckr";

MySqlConnection con = new MySqlConnection(connectionSetting);

con.Open();

MySqlCommand command = new MySqlCommand("insert into log(strLog) values('log1')", con);

command.ExecuteNonQuery();

con.Close();
}
}

Answer Source

Connection pooling is a technique of creating and managing a pool of connections:

Here's the additional info about connection pooling

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download