473,399 Members | 2,159 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,399 software developers and data experts.

database connection loss


Hallo!

I'm working with C# .NET 2.0, implementing Client/Server Applications which
are connecting via Network to SQL-Server or Oracle Databases.
To stay independent from the underlaying Database I use
System.Data.Common.DBConnection and .DBCommand.

How can I keep aware from connection losses (network not availeable,
db-server not available...)?
Are there any strategies to detect this broken connections, and how can I
implement reconnecting to the database?

The only solution I figured out, is creating a thread which frequntly
performs a SELECT 1 (MSSQL) or SELECT 1 FROM DUAL (Oracle) within a
try-catch block. When an exception occurs I have to send my other
worker-threads to sleep, till I'm able to reopen the database connection and
my Select-Statement works again. Then I have to trigger the other threads to
reopen their connections and continue working (every thread gots his own
DBConnection).

For me this seems a little bit to complicated and insecure.
It also could happen that one of the worker threads gots a timeout due
locking or delayed server responstime, and will loose his Connection in fact
of this exception. Such, or similar problems I can not get handled with my
solution.

Are there any suggestions, patterns or automathisms with ADO 2.0?

with friendly regards

Martin
Apr 12 '06 #1
3 2096
There are a couple of things you can do outside of ADO to test that the
serveris available and listening on the desired port.

Netstat will tell you if the server is:

1. Available and online
2. Reporting that it is listening on the desired DB TCP/IP ports (i.e.,
SQL server is by default port 1433)

Telnet will tell you:

1. The server is available and online
2. Connection to the desired port is possible

Niether of these solutions will tell you that the server is bottlenecked,
experiencing long queues, in single use mode, or in a unstable state.

In your situation, I would plan worse case and code in that manner.

Make use of transactions, and minimize connectivitiy when possible.
Devise failover solutions that allow for resuming once a failed thread
restarts.
Log exceptions for later review
Request SLA from Network Support along with best times for processing
Prepare data prior to committing it
Open Connecion
store prepared data locally with a processed flag
create a transaction
commit data
complete transaction
Close connection
mark prepared data as processed
remove local cache

:Failover

Open locally cached prepared data
Open connection
create transaction
commit data
complete transaction
Close Connection
mark prepared data as processed
remove local cache
"Martin B" <ma************@gamed.com> wrote in message
news:44***********************@newsreader.inode.at ...

Hallo!

I'm working with C# .NET 2.0, implementing Client/Server Applications
which are connecting via Network to SQL-Server or Oracle Databases.
To stay independent from the underlaying Database I use
System.Data.Common.DBConnection and .DBCommand.

How can I keep aware from connection losses (network not availeable,
db-server not available...)?
Are there any strategies to detect this broken connections, and how can I
implement reconnecting to the database?

The only solution I figured out, is creating a thread which frequntly
performs a SELECT 1 (MSSQL) or SELECT 1 FROM DUAL (Oracle) within a
try-catch block. When an exception occurs I have to send my other
worker-threads to sleep, till I'm able to reopen the database connection
and my Select-Statement works again. Then I have to trigger the other
threads to reopen their connections and continue working (every thread
gots his own DBConnection).

For me this seems a little bit to complicated and insecure.
It also could happen that one of the worker threads gots a timeout due
locking or delayed server responstime, and will loose his Connection in
fact of this exception. Such, or similar problems I can not get handled
with my solution.

Are there any suggestions, patterns or automathisms with ADO 2.0?

with friendly regards

Martin

Apr 12 '06 #2
Thanx for your immediate Reply!

For me it's rather impossible to Close and Open the Connection at any
transaction. I have to process 5 transactions per second so it seems to
decrease my performance despite connection pooling.

What I wanted to know is, how to implement a simple and secure reconnect
policy in my program code.
It doesn't matter for me that there will be a data-loss on connection abort,
important is that after reestablishing and fixing the network or database
link physically (it's not my job) my program recognizes as soon as possible
the availability and restarts with his work.
That means removing the broken connection object (Close, Dispose I don't
know exactly) and recreating a new Connection for further transactions.
During the Connection isn't available for me my program should stand in
waiting position, ignoring all user events and testing the connection
periodically.

So the topics of relevance:

1.) detection of connection loss in my code (avoiding thread or program shut
down)
2.) cycling test of db availability
3.) reopen connections on availability

This points should work for several threads which are owning an connection
object for each of them.

with friendly regards

Martin

"AMDRIT" <am****@hotmail.com> wrote in message
news:ec****************@TK2MSFTNGP03.phx.gbl...
There are a couple of things you can do outside of ADO to test that the
serveris available and listening on the desired port.

Netstat will tell you if the server is:

1. Available and online
2. Reporting that it is listening on the desired DB TCP/IP ports
(i.e., SQL server is by default port 1433)

Telnet will tell you:

1. The server is available and online
2. Connection to the desired port is possible

Niether of these solutions will tell you that the server is bottlenecked,
experiencing long queues, in single use mode, or in a unstable state.

In your situation, I would plan worse case and code in that manner.

Make use of transactions, and minimize connectivitiy when possible.
Devise failover solutions that allow for resuming once a failed thread
restarts.
Log exceptions for later review
Request SLA from Network Support along with best times for processing
Prepare data prior to committing it
Open Connecion
store prepared data locally with a processed flag
create a transaction
commit data
complete transaction
Close connection
mark prepared data as processed
remove local cache

:Failover

Open locally cached prepared data
Open connection
create transaction
commit data
complete transaction
Close Connection
mark prepared data as processed
remove local cache
"Martin B" <ma************@gamed.com> wrote in message
news:44***********************@newsreader.inode.at ...

Hallo!

I'm working with C# .NET 2.0, implementing Client/Server Applications
which are connecting via Network to SQL-Server or Oracle Databases.
To stay independent from the underlaying Database I use
System.Data.Common.DBConnection and .DBCommand.

How can I keep aware from connection losses (network not availeable,
db-server not available...)?
Are there any strategies to detect this broken connections, and how can I
implement reconnecting to the database?

The only solution I figured out, is creating a thread which frequntly
performs a SELECT 1 (MSSQL) or SELECT 1 FROM DUAL (Oracle) within a
try-catch block. When an exception occurs I have to send my other
worker-threads to sleep, till I'm able to reopen the database connection
and my Select-Statement works again. Then I have to trigger the other
threads to reopen their connections and continue working (every thread
gots his own DBConnection).

For me this seems a little bit to complicated and insecure.
It also could happen that one of the worker threads gots a timeout due
locking or delayed server responstime, and will loose his Connection in
fact of this exception. Such, or similar problems I can not get handled
with my solution.

Are there any suggestions, patterns or automathisms with ADO 2.0?

with friendly regards

Martin


Apr 13 '06 #3
MS bugs: nowhere you are told how to work with connections. I guess the best is to
1. open connection
2. transaction
3. close connection

over and over again.

Regards Marcus

PS I have the same problem, open connections will be autoclosed and cannot be reopened (again MS bug).
---
Posted via www.DotNetSlackers.com
Apr 19 '06 #4

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

Similar topics

8
by: Peter Larsson | last post by:
Hi there, I've recently developed a VBA-program in Excel that fetches and presents data from a distant Access database over a wireless peer-to-peer network (both computers running Win XP Pro)....
3
by: markaelkins | last post by:
I want to create a simple user interface to collect the following data and store the data in a SQL database…. Could someone please help me get started? Data to collect from user interface and...
1
by: Sonya | last post by:
Hello, I have trouble connecting to Access database from my web service. Database is located in a subdirectory of where service pages are. Code below produces the following exception: "No error...
3
by: Martin B | last post by:
Hallo! I'm working with C# .NET 2.0, implementing Client/Server Applications which are connecting via Network to SQL-Server or Oracle Databases. To stay independent from the underlaying Database...
5
by: Dennis | last post by:
I am totally confused between Access, SQL Express, and SQL Server and MSDE and OLEDB vs SQL in .net. Please someone tell me if I"m correct in the following: With MSDE installed, I can program...
7
by: wally | last post by:
I have Visual Studio 2005 Pro. I installed SQL Express 2005 and rebooted. But, when I right click on "Data Connections" in the Server Explorer and choose "Create New SQL Server Database..." and...
3
by: Big Charles | last post by:
Hi, We have developed an ASP.NET web application and are planning to host it in an external Server, which provides us a good bandwidht. We need to put he web application outside because the...
6
by: mpmason14 | last post by:
I found a vbscript on vbskrypt.com that allows me to inventory the software installed on my computer and puts it in an Access database. problem: the script only finds those programs installed...
8
by: mark_aok | last post by:
Hi all, I have a split database. Both the forms, and the tables are stored on a shared network drive (this is Access 2003). The users use the forms, and the tables on the network drive, there...
8
by: Rahul | last post by:
Hi Everyone, I'm currently developing a class for a database, each object of the class will establish a connection to the database on a remote server and and all of this happens on the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...
0
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...
0
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...
0
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,...
0
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...

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.