"use" in mysql connection

im is running on a C # login server with mysql, and I have a question: I saw on the Internet that the correct way to use MySqlConnection and execute queries uses the "use" of the statute as follows:

using (SqlConnection con = new SqlConnection(CNN_STRING))
{
    using (SqlCommand cmd = new SqlCommand("COMMAND", con))
    {
        //do something
    }
}

Well, if I use this, the connection will be closed and open every time, right? The problem is that opening a connection takes about 200 ms, will it be this time every time I try to execute a request?

+4
source share
3 answers

Well, if I use this, the connection will be closed and open every time, right?

It will be closed automatically. You still need to open it before using it.

, 200 , , ?

, , .NET, . , , , , .

, , .

, . , , ( ) .

+4

! , . .

0

This should open your connection and properly dispose of it at the end of the block using.

using (SqlConnection con = new SqlConnection(CNN_STRING))
{
    SqlCommand cmd = new SqlCommand("COMMAND, con);
    //do something
}
0
source

Source: https://habr.com/ru/post/1613565/


All Articles