locked
C# Multiple thread connect to one SQL Server database, dbconnection.open hang RRS feed

  • Question

  • my code process is as below:
    1. create database connection
    2. create database dbCommand
    3. call ExecuteReader and get reader (parse database data)
    4. dbCommand cancel
    5. reader close
    6. database connection close

    my connection string is as below:
    string SQLConnection = "Pooling=true;Max Pool Size=1000;Min Pool Size=0;Server=192.168.0.111;Database=MySqlDB;Trusted_Connection=SSPI;Connect Timeout=5";
    SqlConnection sqlConnection = new SqlConnection(SQLConnection);

    The above processing will be done in parallel in multiple threads, one time hang in the db.open()
    So why?

    Thursday, July 9, 2020 1:37 AM

All replies

  • Hi Hi, Shirley,

    Please refer to below,this may be useful to you .

    private void button4_Click(object sender, EventArgs e)      
    		(            
    		 if (button4.Text = 'suspend')            
    		    (                toolStripStatusLabel1.Text ='suspend...';                
    		       button4.Text = 'continue';                
    			   for (int i = 0; i < threads.Length; i++)                
    		       (  Thread thr = threads[i];                   
    		           if (thr.ThreadState = ThreadState.Running)                   
    		             (  thr.Suspend()        --Check whether the thread status is running, if yes, use Suspend method to suspend it
    		                 )               
    						      )            
    							           )            
    		else            
    		(toolStripStatusLabel1.Text = 'start..';                
    		     button4.Text = 'suspend';   
    		        for (int i = 0; i < threads.Length; i++)                
    		           (                    Thread thr = threads[i];                    
    		             if (thr.ThreadState = ThreadState.Suspended)                   
    		                 (  thr.Resume()        
    		         --Check whether the thread state has been suspended, if yes, use the Resume method to resume it    }    
    				 )  
    				      )        
    					      )

    Best Regards

    Echo


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com


    • Edited by Echo Liuz Thursday, July 9, 2020 8:47 AM
    • Proposed as answer by Echo Liuz Thursday, July 16, 2020 5:20 AM
    Thursday, July 9, 2020 8:25 AM
  • Hi Hi, Shirley,

    Has your problem been solved? If it is solved, please mark the point that you 
    think is correct as an answer. This can help others who encounter similar problems.

    Best Regards
    Echo


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com

    Monday, July 13, 2020 7:11 AM