473,739 Members | 4,265 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Database Connection Problem. Please Help

Sam
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_Applicatio nDetails", _
"@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(B yVal 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.Comman dText = sStoredProc
aCommand.Comman dType = CommandType.Sto redProcedure
aCommand.Connec tion = aConnection

aCommand.Parame ters.Add(sVarNa me, iInt)

Return(aCommand .ExecuteReader( CommandBehavior .CloseConnectio n))
Catch e As Exception
Throw New Exception(e.Mes sage, e)
Finally
If aConnection.Sta te.Open = True Then
aConnection.Clo se()
aCommand.Dispos e()
End If
End Try

End Function
Jul 15 '06 #1
5 1638
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_Applicatio nDetails", _
"@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(B yVal 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.Comman dText = sStoredProc
aCommand.Comman dType = CommandType.Sto redProcedure
aCommand.Connec tion = aConnection

aCommand.Parame ters.Add(sVarNa me, iInt)

Return(aCommand .ExecuteReader( CommandBehavior .CloseConnectio n))
Catch e As Exception
Throw New Exception(e.Mes sage, e)
Finally
If aConnection.Sta te.Open = True Then
aConnection.Clo se()
aCommand.Dispos e()
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.
Jul 15 '06 #2
Sam,

I find it strange that it does 100 rows. The function is called and closes
and even disposes the connection immidiatly. How can it than after that read
100 rows?

Cor
Jul 16 '06 #3
Sam
Cor,

Sorry for the confusion, I have a windows service that first sleep for about
5 minutes then download all records that it needs to be processed into a
table. Then for each of these records, I have to process it (one by one) by
calling one of our class objects which then open database and pull out the
details of that record. What code fragment I posted is from the object class
that pulls out record details and does the process.

Chris who replied to this post suggested that I should maintain the
connection until all records are processed instead of open then closed for
each record. The problem I'm facing is that the object that does the
processing opens the database, create datareader and then close the
connection again. Unless I create my own data reader and connection and pass
this data reader from my windows service to this object, I can't really
maintain the same connection.

Regards,

Sam













"Sam" <as****@yahoo.c omwrote in message
news:u1******** ******@TK2MSFTN GP03.phx.gbl...
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_Applicatio nDetails", _
"@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(B yVal 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.Comman dText = sStoredProc
aCommand.Comman dType = CommandType.Sto redProcedure
aCommand.Connec tion = aConnection

aCommand.Parame ters.Add(sVarNa me, iInt)
Return(aCommand .ExecuteReader( CommandBehavior .CloseConnectio n))
Catch e As Exception
Throw New Exception(e.Mes sage, e)
Finally
If aConnection.Sta te.Open = True Then
aConnection.Clo se()
aCommand.Dispos e()
End If
End Try

End Function

Jul 17 '06 #4
Sam
Chris,

Thanks for your great suggestions. The problem I'm facing is that the
process that pulls details of each record is a class object which uses
datareader to pull data out from our database. I guess if I want to maintain
a connection till all records have been processed, I will need to create a
method which takes a data reader and maintain a connection myself

"Chris" <no@spam.comwro te in message
news:OX******** ******@TK2MSFTN GP05.phx.gbl...
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
SqlDataReade r, 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
applicationI D
============== =============== ==
Dim appReader As SqlDataReader

appReader = GetDataReader(" user_Applicatio nDetails", _
"@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(B yVal sStoredProc As String, ByVal
sVarName As String, ByVal iInt As Integer) As SqlDataReader

Dim aCommand As New SqlCommand

Try

aConnection = OpenConnection( aConnection) '
OpenConnecti on returns sqlconnection

aCommand.Comman dText = sStoredProc
aCommand.Comman dType = CommandType.Sto redProcedure
aCommand.Connec tion = aConnection

aCommand.Parame ters.Add(sVarNa me, iInt)
Return(aComman d.ExecuteReader (CommandBehavio r.CloseConnecti on))
Catch e As Exception
Throw New Exception(e.Mes sage, e)
Finally
If aConnection.Sta te.Open = True Then
aConnection.Clo se()
aCommand.Dispos e()
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.

Jul 17 '06 #5
Sam,

What I find strange that it is a kind of inbetween function, it does
something but not complete, would it not better to understand if your method
would return a complete datarow (or whatever represtenting that) instead of
a datareader?

Cor

"Sam" <as****@yahoo.c omschreef in bericht
news:O8******** ******@TK2MSFTN GP05.phx.gbl...
Cor,

Sorry for the confusion, I have a windows service that first sleep for
about 5 minutes then download all records that it needs to be processed
into a table. Then for each of these records, I have to process it (one by
one) by calling one of our class objects which then open database and pull
out the details of that record. What code fragment I posted is from the
object class that pulls out record details and does the process.

Chris who replied to this post suggested that I should maintain the
connection until all records are processed instead of open then closed for
each record. The problem I'm facing is that the object that does the
processing opens the database, create datareader and then close the
connection again. Unless I create my own data reader and connection and
pass this data reader from my windows service to this object, I can't
really maintain the same connection.

Regards,

Sam













"Sam" <as****@yahoo.c omwrote in message
news:u1******** ******@TK2MSFTN GP03.phx.gbl...
>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
SqlDataReade r, 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
applicationI D
============== =============== ==
Dim appReader As SqlDataReader

appReader = GetDataReader(" user_Applicatio nDetails", _
"@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(B yVal 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.Comman dText = sStoredProc
aCommand.Comman dType = CommandType.Sto redProcedure
aCommand.Connec tion = aConnection

aCommand.Parame ters.Add(sVarNa me, iInt)
Return(aComman d.ExecuteReader (CommandBehavio r.CloseConnecti on))
Catch e As Exception
Throw New Exception(e.Mes sage, e)
Finally
If aConnection.Sta te.Open = True Then
aConnection.Clo se()
aCommand.Dispos e()
End If
End Try

End Function


Jul 18 '06 #6

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

Similar topics

3
2585
by: James | last post by:
Please help - getting very desperate! Sun, 12 October 2003 05:39 I have PHPDEV 4.2.3 from Firepages.com.au as the upgrade to 4.3.0 did not work. I also had an abortive download from PHP.NET as I could not configure Apache myself. The REAL problem is that PHPmyAdmin works and sees my test database Wines.... But my PHP program does not!
1
1583
by: YERVANT | last post by:
I have a problem with my connection. My computer is a customer Windows 2000 Professional, I installed IIS into my computer. I want use a connection with a database into the server. ( The server is Windows 2000 Server). When I put the database into a folder in my computer like this (C:\toto\cli_sat.mdb) The connection function:
1
1901
by: James | last post by:
I'm having this problem with an ASP.NET web service (C#)... can anyone help please? My connection string is: Provider=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:System Database=" + Server.MapPath("Secured.mdw") +@"; Data source=" + Server.MapPath("TMIData.mdb") +@"; User ID=james; Password=pass; Persist Security Info=true
13
4334
by: Joner | last post by:
Hello, I'm having trouble with a little programme of mine where I connect to an access database. It seems to connect fine, and disconnect fine, but then after it won't reconnect, I get the error "operation is not allowed when object is open" so I take out the line of code: BookDetails.Connection1.Open and it comes up with the error "operation is not allowed when object
18
9148
by: surfrat_ | last post by:
Hi, I am having the following problems in getting Microsoft Visual Studio 2005 Professional to link to an Access .mdb database. Please help me to sort this out. Problem 1: The Microsoft page "How to: Connect to Data in an Access Database"
5
2804
by: igotyourdotnet | last post by:
I'm trying to add a web part to my page and when I run my page with the web part I get this error: An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified) Now the entire web site is...
5
14433
by: Glen Buell | last post by:
Hi all, I have a major problem with my ASP.NET website and it's SQL Server 2005 Express database, and I'm wondering if anyone could help me out with it. This site is on a webhost (WebHost4Life) and was running fine and dandy, until I decided I needed to add some additional stored procedures to the database.
5
3397
by: Usman Jamil | last post by:
Hi I've a class that creates a connection to a database, gets and loop on a dataset given a query and then close the connection. When I use netstat viewer to see if there is any connection open left, I always see that there are 2 connections open and in "ESTABLISHED" state. Here is the piece of code that I'm using, please tell where I'm doing it wrong. Since this class is being used at many placed in my actual web based application that...
39
5865
by: alex | last post by:
I've converted a latin1 database I have to utf8. The process has been: # mysqldump -u root -p --default-character-set=latin1 -c --insert-ignore --skip-set-charset mydb mydb.sql # iconv -f ISO-8859-1 -t UTF-8 mydb.sql mydb_utf8.sql mysqlCREATE DATABASE mydb_utf8 CHARACTER SET utf8 COLLATE utf8_general_ci;
0
8969
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9479
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9337
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9266
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9209
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8215
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6754
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4570
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2748
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.