Solved

mysql  maximum connection error

Posted on 2009-07-10
7
253 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
Comment Utility
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
Comment Utility
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
Comment Utility
The using statements should take care of both close() and dispose() of the objects also...
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 1

Author Comment

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

Author Comment

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

Author Closing Comment

by:CahitEy
Comment Utility
Thanks
0
 
LVL 59

Expert Comment

by:Kevin Cross
Comment Utility
CahitEy,

You are most welcome.

Thank you very much for the points.

Happy coding!

Regards,
Kevin
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

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…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now