This is a migrated thread and some comments may be shown as answers.

Reconnect to database after connection broke

3 Answers 155 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Sepp
Top achievements
Rank 1
Sepp asked on 20 Feb 2013, 01:42 PM
This is my first post here in this forum and I hope that I'm right here ;)

At the moment I write a Windows service that loads data from a third party system and saves them to an Oracle database. From time to time the database must be rebooted or the network is not available any more, so the database connection gets broken. This can happen during the service doing nothing and also while executing queries.

Is there any possibility for an automatic reconnect of the current context? I must say that I create only one context at the beginning of the service lifetime. Or do I have to create a new context each time I want to exchange data with database?

3 Answers, 1 is accepted

Sort by
0
Ralph Waldenmaier
Telerik team
answered on 21 Feb 2013, 08:56 AM
Hi Sepp,

Based on the described setup, I would recommend always using a new context in your windows service. We can not provide a retry mechanism on the connection since we do not know what has already been executed in your business logic. I would recommend implementing the retry logic in your business layer. 
You might find this link interesting describing how to maintain the context in web environments.

Also please have a look at this blog post, describing the various connection pool types and why you should at choose ADOManaged or ADO for Oracle environments.

I hope this information is helpful for you.
Feel free to ask if you have any other question.

Kind regards,
Ralph
the Telerik team
Q3'12 SP1 of OpenAccess ORM packs Multi-Table Entities mapping support. Check it out.
0
Sepp
Top achievements
Rank 1
answered on 22 Feb 2013, 02:37 AM
Hello Ralph,

Yes, you helped me a lot with your post! I did not have the "right" pool type, so I changed it. Thanks for that!

With that I have a potential improvement of OpenAccess: why not showing the user a hint in the Model Settings window when selecting Oracle as backend?! In this hint there should be a link to this and that. What about that idea?

But I have some more questions that came up with this problem:
- Is it possible to use more than one context instance? Are there any pitfalls?
- Do you have any idea how to detect that the connection to the Oracle database is broken? There are many Oracle error codes and I don't know which of these are relevant for my problem. Is there any flag in the context object? I did not find anything that would help me.
- What exactly returns OpenAccessContextBase.Connection if a connection pool is used? (in my case Oracle manages the connection pool)

Once again, thanks for your answer ;)

Best regards,
Sepp
0
Ralph Waldenmaier
Telerik team
answered on 25 Feb 2013, 08:15 AM
Hi Sepp,

Thank you for your suggestion regarding the Model Settings Dialog. I will forward your suggestion.

To your questions:
1. No there are not pitfalls in using more than one context. You can use this approach safely.
2. You can always try to execute an arbitrary select script and catch any exceptions to see if the connection is open. Alternatively, you can do a simple count on one of your Domain Classes. This will also create a connection against the database. If you catch errors here, you should be able to see if your connection works or not.
3. The Connection property on the OpenAccessContextBase is returning a OAConnection. This is basically a wrapped DbConnection object obtained from the connection pool from the underlying ADO driver. Please also have a look into our offline API documentation, where you can find more details about this property.

Do come back in case you need further assistance.

Regards,
Ralph
the Telerik team
Q3'12 SP1 of OpenAccess ORM packs Multi-Table Entities mapping support. Check it out.
Tags
General Discussions
Asked by
Sepp
Top achievements
Rank 1
Answers by
Ralph Waldenmaier
Telerik team
Sepp
Top achievements
Rank 1
Share this question
or