Close GPRS connection that was opened by another application - c#

I'm developing an application that in the event of losing connectivity restarts the phone.
Before this step we'd like to close any open connections through Connection Manager. I understand we can use ConnMgrReleaseConnection to release a connection but is it possible to get the Connection handle if the connection was established through another application?
If connection manager fails to close the connection we can then perform a RASHangup but we'd like to attempt it through ConnectionManager first.

Nope, there's no way to do it through connection amanger. The handle ConnMgrReleaseConnection wants is the one returned from the call to ConnMgrEstablishConnection. Presumably the "other" application called this and has the handle, but even if that app could give you the handle, it would be invalid in your own process space anyway.
Generally it would be bad form to do something like this anyway, as I'd assume that the app that openened the connection would expect it to always be open once it had asked for it. Forcibly closing it (even through RAS) without that app knowing could lead to unexpected behavior. Probably not a huge issue for you if you're just going to restart the phone, but if you have any sort of control over that other app, I'd add handling where you can tell it to close it's connections.

Related

SQL Server : keep connection open because I will need to check table state every second

I have a need where I will need to check a specific table on a remote SQL Server for any data changes.
And this I will need to do as soon as it is possible e.g almost every second so that as soon as a change happens, I can do something about it on another server where I am running this watcher program.
I think opening a connection every second to remote may be expansive, and keeping a connection open for a very long time is considered a bad practice. What is the best option for me?
Server 1 has a watcher program, which will monitor data change activity on
Server 2 (remote server). I must know about data change as soon as it happens on Server 2 and then perform some actions on Server 1
Thanks
I think opening a connection every second to remote may be expensive,
It's not. Read about Connection Pooling. The network connection and SQL Server session are not closed when you call SqlConnection.Close() or SqlConnection.Dispose(). The underlying connection is simply returned to the pool for later use.
But if the connection is lost or the server fails, you will get a new connection from the pool, so it's vastly more reliable than keeping a single connection open.

Should I leave a database connection open for an event handler?

I am writing an application in C# that will connect to a PostgreSQL database via ODBC. The database will be on the same machine as my application. My application will have an event handler that could fire a few times a second. The handler will write two values into a database table. I'm wondering if I should open a database connection once when the application starts for the event handler to use, or if I should open it inside the event handler and close it when the handler is finished with its work.
If connection pooling is used, the question becomes moot, since an existing connection would always be used if one is available, and I could just open and close the connection without worrying about slowing down my application. But it seems that the ODBC driver for PostgreSQL does not support connection pooling. Or does it?
I'm using the PostgreSQL Unicode driver version 9.03.04.00.
Thank you very much.
Never open and close a database connection for every request. It may work as long as there is little traffic, but it is a receipe for disaster otherwise.
You can use an external connection pool like pgBadger, but if that is overkill in your case, just leave the connection open. With several writes per second that is clearly the right thing to do.

Power Off GPRS on windows mobile 6.1

I'd like to turn off GPRS connection when I close my aplication.
I looked for other problems but:
Power On/Off GPRS on windows mobile
When I use OpenNetCF and set radio.RadioState = RadioState.Off; for PhoneRadio I disable all phone module (I could turn off and on but after that user have to type PIN again)
Other solution:
Closing GPRS Connections On Windows Mobile
recommend to use RAS which is deprecated in WinMo and there is no good documentation.
Is there any posibility to turn off GPRS connection in other way (and if its;s possible using managed C# not P/Invoke and winAPI)?
Your application is not responsible for closing the connection, just as it's not responsible for opening it. Under WinMo, the piece that is responsible for connection is the Connection Manager (CM) and, generally speaking, all requests for connection actions goes through it. For example, when you open something like an HttpWebRequest, CM is notified and it opens a connection for you. Closing a connection, is also out of your app's purview. You can tell CM that you no longer require a connection, but CM is looking for all apps, so it's not going to just shut the connection down. It's going to keep it alive for some period in the event it is either in use or might be called by other application.
This is just how it is. You can't end-run around it with one exception. As the answer you link to says, you can use RAS to forcibly close the connection, but it's not something that I'd recommend becasue it can make CM angry and leave things in a indeterminate state.

Why disconnect from a database?

Background info: I'm coding with C#, using Microsoft SQL Server for databases.
I didn't find much on Google on the subject, so I'm asking here: should I always close a connection to my database after performing a query?
I'm torn between two solutions (maybe better ones exist...):
either open the connection before querying, then close it right after the SQL query
or open the connection at the start of my application, and before each SQL query check if the connection is still up and reopen it if needed.
In the past, I used the first solution but I discovered that opening a new connection can take quite some time (especially over a VPN connection to my LAN opened through 3G), and that it would slow down my application. That's why I decided to go with the second solution (in that case, my connection should be always up if we forget about time-out) and noticed some better performances.
Do I need to close the connection at the end of my application or can I forget about it?
Yes, you should close your connection after each SQL query. The database connection pool will handle the physical network connection, and keep it open for you. You say that you found that opening a connection can take some time - did you find that the application was really doing that multiple times?
(I hope your real application won't be talking directly to the database over 3G, btw... presumably this is just for development purposes...)
One important thing to remember is that there is a unique connection pool for each unique connection string you use... so always use the same connection string unless you need to connect to a different database (or have unique requirements).
Here is a good document on connection pooling with System.Data.SqlClient.SqlConnection.
This will heavily depend on how many clients you anticipate will need to connect to the database. Leaving the connection open, could prevent another user from accessing the DB while they wait for an open connection.

IBM JMS connection

I'm currently working in C# and I need to check the state of the JMS connection that i made (whether it's connected / disconnected). I'm sure that I can connect and disconnect succesfully..its just that i need to display the status of the connection in my UI.
Is there any properties of the JMS connection that states connection status? Or is there any other method that i can use to check the connection status?
Thanks for your help. :)
Currently, I'm using the ExceptionListener to listen for any exceptions and a flag will be set to false when any exception is catched. And when I'm connecting, I will set the flag to true vice versa when i disconnect, I will set the flag to false.
This flag will be used by my UI to detect whether the connection is up or not.
However I was thinking that if theres any property / methods of the IBM connection which can be used to show the state of the connection as its a much better solution. For SonicMQ, theres .getConnectedState() which shows whether the connection is active or inactive. I was wondering whether if IBM have something similar to SonicMQ?
You can use the Connection.setExceptionListener() method to be notified asynchronously of exceptions detected in the connection. If a problem is detected the onException() method is called.
Be sure to set the FAILIFQUIESCE property on the factories and destinations so that your connection is notified and closed in an orderly fashion when the QMgr is shut down by the administrator.
In v7 of WMQ it is possible so enable session reconnection in the transport. In this case, the application may not be aware that the connection was interrupted but you can treat it as having been continuously connected.
Note that, for the most part, exceptions are driven by the application's API calls. So if the connection is lost, you may not know about it in real time but rather find out when an API call is made. If the application sits idle for long periods of time and you want a real-time display of connection status. Please see also "How to find out if JMS Connection is there?" for more on that topic.
WMQ v7 has options to reconnect the client automatically. You must be using v7 at both the client and the server for this to work. Since v6 is end-of-life as of Sept 2011, it is best if you develop this app on v7. You can download the v7 client as SupportPac MQC7. When JMS client reconnect is enabled, the application may not be aware of the connection activity except as a delay in responding to an API call while the connection is rebuilt. The length of that delay depends on channel tuning set by the administrator and in the connection factory.

Categories

Resources