How can UNCLOSED connection be found in OC4J/Oracle? - oracle10g

I fixed and use Connection Pool to get the DB Connection from JSP to Oracle Database now.
But then I found out from the OC4J console at once that there are many UNCLOSED/NOT-CLOSED connection.
I am using OC4J 9.0.4.1 and Oracle 10g. Is there any effective way to find out the location or area that the connection is not closed.
In addition, I would like to know the followings:
1) The UNCLOSED connection means the Connection or ResultSet or Statment ?
2) IF Connection for the ResultSet and Statement is closed, the corresponding ResultSet and Statement are closed automatically too ?

I'd expect that this is easiest to detect on the server side - one assumes (!) that there is a 'show me all the open connections' report or command on the server that should show up a list of those connections together with the last executed SQL on that connection (am coming from the MSSQL side of things here - this doesn't sound like too much of a stretch, tho').
Unclosed means that the connection has not been closed.

Related

SQL workbench This connection has been closed in few minutes

I use SQL workbench to connect postgresql. But I frequently get following error
This connection has been closed.
when ever I kept the window idle for 2-3 minutes.
I am not sure where to the change the settings. Please help me .
Version : Build 118.7
If the server is configured to disconnect idle connections, you can configure a statement that is sent to the database server in regular intervals.
This is done in the connection profile. Click on the "Connect scripts" button:
Connection dialog
Then enter a statement for "Statement to keep connection alive".
Connect scripts
In the "Idle time" you can configure how often the statement should be executed. "1m" means that it's run every minute unless you run statements manually (or do something in the DbExplorer)
This should prevent the server to disconnect your session.

How to disconnect all JDBC connections on Glassfish and unlock H2 database?

I'm running a Glassfish 4.1 server with a H2 database in tcp/multi-user mode. I'm trying to programmatically update tables within a singleton bean. I always get the following exception:
org.h2.jdbc.JdbcSQLException: Timeout trying to lock table "GLOBALS"; SQL statement: ALTER TABLE "PUBLIC".GLOBALS ADD STARTFLAG VARCHAR(512) [50200-176]
I know that the table is locked, since one of the container-managed entity managers seems to have an open connection on that table. But at the time of the alter table statement, there would be no need for any connection...
Therefore I am wondering if there is any possibility to close all jdbc connections using container-managed JPA ?
Here's the initialization string I am using to start/connect to the H2 database:
jdbc:h2:tcp://localhost/~/datastore/database;AUTO_SERVER=TRUE;MVCC=TRUE
I already tried to close the container-managed entity manager and the
entity manager factory (but I think this is not the correct approach,
since it's handled by the container) before the update statements are
executed.
I tried to detach the managed objects before the update statements
are executed.
I tried to add the MVCC=TRUE option (multi version concurrency).
Also tried to set FILE_LOCK=NO, but then I get another exception which tells me that this combination of options is not valid.
but without success so far...
Any ideas highly appreciated - thanks in advance!
Solution that comes to my mind is shutdowing server and reopen connection again.
If you are using java configuration you can use server.stop()
import org.h2.tools.Server;
...
// start the TCP Server
Server server = Server.createTcpServer(args).start();
...
// stop the TCP Server
server.stop();
If you're creating db via your URL. You can create a bat file and call it programatically from your application.
java org.h2.tools.Server -tcpShutdown tcp://localhost:9092
You can find more information from H2 Website

Crystal Reports in C#

Actually i try to make the crystal report of my database table values, so far i reached the primary stage of SQL connection. whenever i choose the new connection it seems to produce some errors like,
A network-related or instance0specific error occured while establishing a connection to SQL Server. The serve was not found or was not accessive. Verify that the instance name is correct and that SQL Server is configured to all allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
can anyone pls guide me to generate the crystal report.
Thank you,
Arunkumar M
From the error message you seem want to connect over Named Pipes. Check in SQL Server Configuration Manager if you have enabled Named Pipes
Also you can use PortQueryUI [http://www.microsoft.com/en-us/download/details.aspx?id=24009] to see if your SQL Server is from your location accesible and if it listens on Named Pipes.
Alternatively you could try to connect over TCP/IP port 1433. Also check in SQL COnfiguration Manager if you have TCP/IP enabled and check in PortQueryUI if SQL Servers TCP ports are open.

How does ODBC pull database connection details?

I currently have a Macro which is connecting to a sybase database using ODBC. It's making the connection by running the following:
Set conX = wrkODBC.OpenConnection("Connection1", , True, strConn)
where strConn = "ODBC;DSN=Server_Name;APP=Daily Task;DB=db_name;UID=uname;PWD=pwd;"
The problem I am having is that this connection is working for some Server_Name's but not others. When it doesn't work I get a Error "3146 - ODBC--call failed".
What I don't understand is where it is pulling the server details from. So for example, when using embarcadero rapid to connect to a sybase database, it will use the sql.ini file to pull the server connection details based on the server_name.
I have checked and all the Sybase Servers I am testing are in the sql.ini file and my env variables are pointing to the correct sybase version. I've checked ODBC and it is only picking up a SQL Server driver.
Can anyone please explain how ODBC pulls the server name connection details? I don't understand why it works for some server names, but not others (FYI, I have tested the uname and pwd is rapid to make sure it is correct).
Any information would be much appreciated.
So, the issue was that I was looking at my odbc connections under control panel. I should mention that I am on windows 7. What I had to do was update my ODBC connection details here:
C:/Windows/SYSWOW64/odbcad32.exe
--This is for 32bit!
This had some connections set up which is why I could connect to some servers but not all of them.

Does database connection stay opened except for errors and explicit closure?

Assuming that no statements to close the connection are made before my script ends and no exception is encountered before closing the connection, does the database's connection stay open?
I'm connecting to the database programmatically via Python Psycopg2 and via Java JDBC4 driver.
Not entirely sure what you want exactly, but let's try:
You can see the connections that exist at any time with PGAdmin or this SQL command
SELECT * FROM pg_stat_activity;
It should be fairly simple to spot when - for your specific use case - the connection closes.
If an SQL query is running at the time you close a connection, I think it will run to completion, ie the backend serving it will remain alive, even if the connection is closed from the client side.