Advertisement

08.29.2008 at 03:44PM PDT, ID: 23690336
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.3

Locking MySql Table from C#;

Asked by gvector1 in Visual Studio, MySQL Server, C# Programming Language

I am attempting to lock a mysql table from c# and have successfully done so, with one problem.  I thought that ideally the table that I lock, would stay locked until I explicitly give the "Unlock Tables" command.  The reason I ask is that I have to execute a select query and an update query on a table before allowing anyone else to access it.  It appears that within my application(2 instances running), I can lock a table from the first instance, attempt to read a value from that table from the second instance(which hangs), and the second I read a value from the first instance the second instance unhangs and completes the execution.  It seems that the table lock is released the moment a command is given to that table from the locking instance.  Any insight on this?????????????????Start Free Trial
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:
//G1.conn1 returns a new instance of a connection to the database.		
 
                private void btnLock_Click(object sender, System.EventArgs e)
		{
			MySqlCommand cmd = new MySqlCommand("Lock Table TestTable write, TestTable as t1 write", G1.conn1);
			G1.TryNonQueryStatic(cmd);
		}
 
		private void btnUnlock_Click(object sender, System.EventArgs e)
		{
			MySqlCommand cmd = new MySqlCommand("Unlock Tables",G1.conn1);
			G1.TryNonQueryStatic(cmd);
		}
 
		private void btnWrite_Click(object sender, System.EventArgs e)
		{
			Double dd;
			if((txtWrite.Text.Length > 0)&&(Double.TryParse(txtWrite.Text,System.Globalization.NumberStyles.Number,null,out dd)))
			{
				MySqlCommand cmd = new MySqlCommand("Update testtable as t1 set testdouble = " + Double.Parse(txtWrite.Text).ToString(),G1.conn1);
				int affected = G1.TryNonQueryStatic(cmd);
				MessageBox.Show("Affected = " + affected.ToString());
			}
			else
				MessageBox.Show("Textbox value is invalid");
		}
 
		private void btnRead_Click(object sender, System.EventArgs e)
		{
			MySqlCommand cmd = new MySqlCommand("Select testdouble from testtable",G1.conn1);
			lblRead.Text = G1.TryScalarStatic(cmd);
		}
[+][-]08.30.2008 at 12:49PM PDT, ID: 22353026

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 14-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09.02.2008 at 06:58AM PDT, ID: 22367331

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 14-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09.02.2008 at 07:00AM PDT, ID: 22367353

View this solution now by starting your 14-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Visual Studio, MySQL Server, C# Programming Language
Sign Up Now!
Solution Provided By: angelIII
Participating Experts: 1
Solution Grade: A
 
 
[+][-]09.02.2008 at 08:04AM PDT, ID: 22367934

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 14-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20081112-EE-VQP-43 / EE_QW_2_20070628