Re: Database Connection Problem. Please Help
- From: Chris <no@xxxxxxxx>
- Date: Sat, 15 Jul 2006 11:13:37 -0500
Sam wrote:
Hi all,
I have a process which first pulls one time all application IDs from a database and stores them in a table(this process works fine everytime). I then loop through the table, one at a time, and use application id to pull details info and process it. For example, if I have 500 records in my table, then I would have to open database 500 times. Also between processing each record, my process sleep 3 seconds.
The problem is that after processing about 100 records, using SqlDataReader, my database connection will starts failing. When I traced the error in my try catch clause, the exception message just say connection fails to open database. I also found that all the subsequent connection also failed to open unless I stop my window service and restart it.
Would some one please give me a hand? I've been trying to find a way to pull all details for all records at once, instead of one at a time but I have not been able to do that.
Thanks in advance for everyone's suggestions
Regards,
Sam
Here is part of my process that pull details of an application base on applicationID
===============================
Dim appReader As SqlDataReader
appReader = GetDataReader("user_ApplicationDetails", _
"@appID", appID)
Do While appReader.Read ' Read applicat
'process data
Loop
If Not appReader Is Nothing Then appReader.Close()
================================
Here is my function that returns sqldataReader
Public Function GetDataReader(ByVal sStoredProc As String, ByVal sVarName As String, ByVal iInt As Integer) As SqlDataReader
Dim aCommand As New SqlCommand
Try
aConnection = OpenConnection(aConnection) ' OpenConnection returns sqlconnection
aCommand.CommandText = sStoredProc
aCommand.CommandType = CommandType.StoredProcedure
aCommand.Connection = aConnection
aCommand.Parameters.Add(sVarName, iInt)
Return(aCommand.ExecuteReader(CommandBehavior.CloseConnection))
Catch e As Exception
Throw New Exception(e.Message, e)
Finally
If aConnection.State.Open = True Then
aConnection.Close()
aCommand.Dispose()
End If
End Try
End Function
Don't open the connection 500 times. Open it once and keep it open, then just use that same connection over and over oand over. Also, you can use the same command object over and over too.
.
- Follow-Ups:
- References:
- Database Connection Problem. Please Help
- From: Sam
- Database Connection Problem. Please Help
- Prev by Date: Re: Can I make my Form visible during a debug session?
- Next by Date: Re: HELP PARRALLEL PORT
- Previous by thread: Database Connection Problem. Please Help
- Next by thread: Re: Database Connection Problem. Please Help
- Index(es):
Relevant Pages
|