Solved

mysql  maximum connection error

Posted on 2009-07-10
7
254 Views
Last Modified: 2012-05-07
Here is my sample connection code and error why it is not closing connection and i always clean them manually? This is workin on webservice
Dim cn As New MySqlConnection
        cn.ConnectionString = ConfigurationSettings.AppSettings("ConnectionString")
        Dim dr As MySqlDataReader
        Dim cmd As New MySqlCommand(sql.resimler, cn)
        cmd.Parameters.Add("?bolum", bolum).MySqlDbType = MySqlDbType.VarChar
        cmd.Parameters.Add("?bolumno", bolumno).MySqlDbType = MySqlDbType.VarChar
        cn.Open()
        dr = cmd.ExecuteReader
        Dim resim = ""
        If dr.Read = False Then
            Return "Yok,"
        Else
            resim += dr.Item(2) & ","
            While dr.Read()
                resim += dr.Item(2) & ","
            End While
        End If
        Return Left(resim, Len(resim) - 1)
        dr.Close()
        cn.Close()

Open in new window

hatamysql.jpg
0
Comment
Question by:CahitEy
  • 4
  • 3
7 Comments
 
LVL 59

Accepted Solution

by:
Kevin Cross earned 500 total points
ID: 24825941
You are returning before the close of the dr and cn objects.  Set your return value to a variable and return it at the very end instead.
0
 
LVL 59

Assisted Solution

by:Kevin Cross
Kevin Cross earned 500 total points
ID: 24826075
More like this:
Dim returnVal As String = "Yok"
 
Using cn As New MySqlConnection(ConfigurationSettings.AppSettings("ConnectionString"))
	Using dr As MySqlDataReader
		Dim cmd As New MySqlCommand(sql.resimler, cn)
		cmd.Parameters.Add("?bolum", bolum).MySqlDbType = MySqlDbType.VarChar
		cmd.Parameters.Add("?bolumno", bolumno).MySqlDbType = MySqlDbType.VarChar
		
		cn.Open()
		dr = cmd.ExecuteReader
		
		If dr.Read Then
			returnVal = dr.Item(2)
			
			While dr.Read()
				returnVal &= "," & dr.Item(2)
			End While
		End If
		
		dr.Close()
	End Using
	
	cn.Close()
End Using
 
Return returnVal

Open in new window

0
 
LVL 59

Expert Comment

by:Kevin Cross
ID: 24826084
The using statements should take care of both close() and dispose() of the objects also...
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
LVL 1

Author Comment

by:CahitEy
ID: 24826097
Thanks for both answers it is ok now , the both answer is the solution
0
 
LVL 1

Author Comment

by:CahitEy
ID: 24826107
i made point 500 to give 250 for each answer thanks again
0
 
LVL 1

Author Closing Comment

by:CahitEy
ID: 31602206
Thanks
0
 
LVL 59

Expert Comment

by:Kevin Cross
ID: 24826121
CahitEy,

You are most welcome.

Thank you very much for the points.

Happy coding!

Regards,
Kevin
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question