473,383 Members | 1,785 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Timing out

Hi,

I've been getting the message:

Timeout period elapsed prior to obtaining a connection from the pool.

I'm using this function on all my pages. Can you see anything incorrect
with the code?

Thanks
Imports System
Imports Microsoft.VisualBasic
Imports System.Web
Imports System.Configuration
Imports System.Data.SqlClient
Imports System.Data

Namespace Data

Public Class dataClass

Public Shared Function GetPage(ByVal courseNumber As Integer,
ByVal lessonNumber As Integer, ByVal pageNumber As Integer ) As IDataReader
Dim strConnection As String
strConnection = ConfigurationSettings.AppSettings
("ConnectionString")

Dim dbConnection As New SqlConnection(strConnection)

Dim queryString As String = "SELECT [tblPage].*, [tblLesson].
[LessonNumber],[tblLesson].[LessonTitle], [tblCourse].[CourseNumber],
[tblCourse].[CourseTitle] FROM [tblPage], [tblLesson], [tblCourse] WHERE ((
[tblPage].[Pa"& _
"geNumber] = @PageNumber) AND ([tblLesson].[LessonNumber] =
@LessonNumber) AND (["& _
"tblCourse].[CourseNumber] = @CourseNumber)) AND tblPage.lessonID
= tblLesson.lessonID AND tblLesson.CourseID = tblCourse.CourseID"

Dim dbCommand As New SqlCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection

Dim dbParam_pageNumber As New SqlParameter
dbParam_pageNumber.ParameterName = "@PageNumber"
dbParam_pageNumber.Value = pageNumber
dbParam_pageNumber.DbType = DbType.Int32
dbCommand.Parameters.Add(dbParam_pageNumber)
Dim dbParam_lessonNumber As New SqlParameter
dbParam_lessonNumber.ParameterName = "@LessonNumber"
dbParam_lessonNumber.Value = lessonNumber
dbParam_lessonNumber.DbType = DbType.Int32
dbCommand.Parameters.Add(dbParam_lessonNumber)
Dim dbParam_courseNumber As New SqlParameter
dbParam_courseNumber.ParameterName = "@CourseNumber"
dbParam_courseNumber.Value = courseNumber
dbParam_courseNumber.DbType = DbType.Int32
dbCommand.Parameters.Add(dbParam_courseNumber)

dbConnection.Open
Dim dataReader As SQLDataReader = dbCommand.ExecuteReader
(CommandBehavior.CloseConnection)
Return dataReader

End Function

End Class
End Namespace

--
Message posted via http://www.dotnetmonster.com
Nov 19 '05 #1
9 956
This sounds like the classic problem of leaking connections to the database.
For this one snippet make sure that whoever's calling GetPage calls Dispose()
or Close() on the returned DataReader.

-Brock
DevelopMentor
http://staff.develop.com/ballen
Hi,

I've been getting the message:

Timeout period elapsed prior to obtaining a connection from the pool.

I'm using this function on all my pages. Can you see anything
incorrect with the code?

Thanks

Imports System
Imports Microsoft.VisualBasic
Imports System.Web
Imports System.Configuration
Imports System.Data.SqlClient
Imports System.Data
Namespace Data

Public Class dataClass

Public Shared Function GetPage(ByVal courseNumber As
Integer,
ByVal lessonNumber As Integer, ByVal pageNumber As Integer ) As
IDataReader
Dim strConnection As String
strConnection = ConfigurationSettings.AppSettings
("ConnectionString")
Dim dbConnection As New SqlConnection(strConnection)

Dim queryString As String = "SELECT [tblPage].*,
[tblLesson].
[LessonNumber],[tblLesson].[LessonTitle], [tblCourse].[CourseNumber],
[tblCourse].[CourseTitle] FROM [tblPage], [tblLesson], [tblCourse]
WHERE ((
[tblPage].[Pa"& _
"geNumber] = @PageNumber) AND ([tblLesson].[LessonNumber] =
@LessonNumber) AND (["& _
"tblCourse].[CourseNumber] = @CourseNumber)) AND
tblPage.lessonID
= tblLesson.lessonID AND tblLesson.CourseID = tblCourse.CourseID"
Dim dbCommand As New SqlCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection
Dim dbParam_pageNumber As New SqlParameter
dbParam_pageNumber.ParameterName = "@PageNumber"
dbParam_pageNumber.Value = pageNumber
dbParam_pageNumber.DbType = DbType.Int32
dbCommand.Parameters.Add(dbParam_pageNumber)
Dim dbParam_lessonNumber As New SqlParameter
dbParam_lessonNumber.ParameterName = "@LessonNumber"
dbParam_lessonNumber.Value = lessonNumber
dbParam_lessonNumber.DbType = DbType.Int32
dbCommand.Parameters.Add(dbParam_lessonNumber)
Dim dbParam_courseNumber As New SqlParameter
dbParam_courseNumber.ParameterName = "@CourseNumber"
dbParam_courseNumber.Value = courseNumber
dbParam_courseNumber.DbType = DbType.Int32
dbCommand.Parameters.Add(dbParam_courseNumber)
dbConnection.Open
Dim dataReader As SQLDataReader = dbCommand.ExecuteReader
(CommandBehavior.CloseConnection)
Return dataReader
End Function

End Class
End Namespace


Nov 19 '05 #2
Thanks. When I'm calling GetPage, I'm binding it to a dataset. So I have:

<ASP:Repeater id="RepeaterPageText" runat="server" DataSource="<%#
Data.dataClass.GetPage(IntCourseNumber,IntLessonNu mber,IntPageNumber) %>">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "pageText") %>
</ItemTemplate>
</ASP:Repeater>

Where would I close the DataReader? Would it be in the Page Load:
Sub Page_Load(sender As Object, e As EventArgs)
Page.DataBind()
End Sub

--
Message posted via http://www.dotnetmonster.com
Nov 19 '05 #3
Call Dispose() after you call DataBind()

-Brock
DevelopMentor
http://staff.develop.com/ballen
Thanks. When I'm calling GetPage, I'm binding it to a dataset. So I
have:

<ASP:Repeater id="RepeaterPageText" runat="server" DataSource="<%#
Data.dataClass.GetPage(IntCourseNumber,IntLessonNu mber,IntPageNumber)
%>">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "pageText") %>
</ItemTemplate>
</ASP:Repeater>
Where would I close the DataReader? Would it be in the Page Load:
Sub Page_Load(sender As Object, e As EventArgs)
Page.DataBind()
End Sub


Nov 19 '05 #4
Thanks so much. I'll try that.

--
Message posted via http://www.dotnetmonster.com
Nov 19 '05 #5
Sorry to hassle you again but just 1 more question.

Would this be the correct way of doing it:

Sub Page_Load(sender As Object, e As EventArgs)
Page.DataBind()
Dispose()
End Sub

I tried to use dbConnection.Close but it doesn't recognize the connection.
Also, is it fine to close the connection in the class as well?

Thanks so much

--
Message posted via http://www.dotnetmonster.com
Nov 19 '05 #6
I'd change it to:

Sub Page_Load()
Dim rdr as IDataReader = Nothing
Try
rdr = GetPage(IntCourseNumber,IntLessonNumber,IntPageNum ber)
RepeaterPageText.DataSource = rdr
RepeaterPageText.DataBind()
Finally
If Not rdr is Nothing then rdr.Close()
End Try
End Sub
-Brock
DevelopMentor
http://staff.develop.com/ballen
Sorry to hassle you again but just 1 more question.

Would this be the correct way of doing it:

Sub Page_Load(sender As Object, e As EventArgs)
Page.DataBind()
Dispose()
End Sub
I tried to use dbConnection.Close but it doesn't recognize the
connection. Also, is it fine to close the connection in the class as
well?

Thanks so much


Nov 19 '05 #7
I have several repeaters on the page that I'm binding the data to.

Can I just bind to the page then close the reader? Sorry, I am new at this.

So something like:

Sub Page_Load()
Dim rdr as IDataReader = Nothing
Try
rdr = GetPage(IntCourseNumber,IntLessonNumber,IntPageNum ber)
Page.DataBind()
Finally
If Not rdr is Nothing then rdr.Close()
End Try
End Sub

--
Message posted via http://www.dotnetmonster.com
Nov 19 '05 #8
The DataReader is a forward-only read-only data access mechanism. So if you
have more than one Repeater than needs to bind to the same result set and
you're using the DataReader, then you're going back to the database for each
one -- this is not good for performance. I'd suggest looking into the DataSet
as an alternate mechanism.

Now, if each of your Repeaters binds to a different set of data from the
database (so different SQL statements), then it's ok to use the DataReader
(you're still going to the database for each one), but you also still need
to call Close() on each one.

Programming's hard. What can I say :)

-Brock
DevelopMentor
http://staff.develop.com/ballen
I have several repeaters on the page that I'm binding the data to.

Can I just bind to the page then close the reader? Sorry, I am new at
this.

So something like:

Sub Page_Load()
Dim rdr as IDataReader = Nothing
Try
rdr = GetPage(IntCourseNumber,IntLessonNumber,IntPageNum ber)
Page.DataBind()
Finally
If Not rdr is Nothing then rdr.Close()
End Try
End Sub


Nov 19 '05 #9
Thanks. That makes sense I am using the same resultset and I'll look into
the dataset. If I use a dataset then I won't need to close any connections
from the page calling the function so that should resolve the connection
leak I'm having right?

Thanks again for all your help.

--
Message posted via http://www.dotnetmonster.com
Nov 19 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: jj | last post by:
I've got one database server that works fine when transferring large amounts of data, but a new one that has been setup seems to want to timeout or drop the connection after a period of time. I've...
10
by: Greg Stark | last post by:
This query is odd, it seems to be taking over a second according to my log_duration logs and according to psql's \timing numbers. However explain analyze says it's running in about a third of a...
7
by: jamie | last post by:
hey all, I am attempting to do motion control for a final project, but I have a concern.... For motion control, timing is everyting, the better it is, the better it works. Currently I am...
9
by: Amir Ghezelbash | last post by:
Hey every body i had a question i am in process of writing an application, where this application needs to check the database on hourly bases to see if they are any information that are needed...
1
by: Novice | last post by:
Hi all, I'm at my wit's end on trying to insert some timing code into the server side code that parses the hashed data contained in the hidden field being submitted to the server I've tried...
3
by: gregory_may | last post by:
I have an application where I am using a System Thread to capture the screen & Broadcast it to clients. Its "working", but the timing on the background thread gets wildly erratic at times. Some...
2
by: Steven D'Aprano | last post by:
The timeit module is ideal for measuring small code snippets; I want to measure large function objects. Because the timeit module takes the code snippet argument as a string, it is quite handy...
2
by: julie.siebel | last post by:
Google apparently ate my original post to this (grr) so this'll be a bit more vague than the initial post, but...*sigh*. Javascript is not my forte, and I apologize for the acky-ness of the...
3
by: CSharpner | last post by:
Is it just me or is everyone having problems with the MSDN site today? It keeps timing out. http://msdn.microsoft.com I've tried from: Oak Ridge, TN A proxy through our company net via...
0
by: Daniel Fetchinson | last post by:
On 4/15/08, Daniel Fetchinson <fetchinson@googlemail.comwrote: BTW, using the following ###################################################################### # CODE TO TEST BOTH...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.