Solved

mysql  maximum connection error

Posted on 2009-07-10
7
255 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
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 …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

809 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