[C++ CLI] MySQL optimalization query tasks

Hello, i want ask one question, what is faster and for duration shorter. When i need do 4 queries in mysql, for example, first INSERT into table, second SELECT this new created row and get autoincrement number and thirt*fourth make next inserts with those values like autoincrement number from new task(ID primary key) etc, its faster when i make one connection for one query, or its possible to make one connection and make multiple MysqlCommand's.

Now i have one MysqlConnection per one query and it working, but when i can make this faster, its be really nice :)

Thanks :)
Why don't you meassure the time each step takes?
System::Diagnosics::StopWatch will be your friend.
https://msdn.microsoft.com/en-us/library/system.diagnostics.stopwatch%28v=vs.110%29.aspx?cs-save-lang=1&cs-lang=cpp#code-snippet-1

Normally I would say one connection and one command should be enough - just change the command text for each query.
its possible to make one connection and make multiple MysqlCommand's.
Yes, making a connection is costly.
Thanks for answers :)

is this correct? i think it works and its faster, because when i do two connection, then i must wait again for connect to mysql, make query and then again connect and do query, now i see only one connection and 2 queries was been maded in maybe half second.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
String^ constring = "datasource=XXXXXXX;username=XXXXXX;password=XXXXX;port=3306";

		String^ komentarquery = "INSERT INTO collabtive.log(user,name,type,action,project,datum) VALUES(" + UserId + ", \"" + text + "\", \"task\", 4, " + projectId + ", \"" + aktualnyCasTimestamp() + "\");";
		String^ query2 = "UPDATE collabtive.tasks SET status=0 WHERE ID=" + taskId + ";";

		MySqlConnection^ komentarconnection = gcnew MySqlConnection(constring);

		MySqlCommand^ komentarcommand = gcnew MySqlCommand(komentarquery, komentarconnection);
		MySqlCommand^ query2cmd = gcnew MySqlCommand(query2, komentarconnection);

		MySqlDataReader^ komentarreader;

		try
		{
			komentarconnection->Open();
			komentarreader = komentarcommand->ExecuteReader();

			while (komentarreader->Read())
			{
				comboBox_zoznamUloh->Items->Add(komentarreader->GetString(3));
				comboBox_zoznamUlohIds->Items->Add(komentarreader->GetString(0));
			}
		}
		catch (Exception^ ex)
		{
			MessageBox::Show(ex->Message);
		}
		komentarconnection->Close();
		try
		{
			komentarconnection->Open();
			komentarreader = query2cmd->ExecuteReader();
		}
		catch (const std::exception&)
		{

		}
		komentarconnection->Close();
		button1->Enabled = false;
Topic archived. No new replies allowed.