2 sessions per user?

adshocker

Well-known member
Joined
Jun 30, 2007
Messages
180
Programming Experience
Beginner
hi all,

i created an application using VB.Net (WinForms) and it has a login page. whenever i log in using my application, it creates 2 sessions for it. i checked the sessions by using [SELECT * FROM v$session WHERE program = myprogramname].

i used similar connection strings each time i connect. i checked this by doing the debug.write(My.Settings.Item("myConnectionString")) and it prints out similar strings on this.

is there anything else that could create a duplicate session?

thanks.
 
i don't think the connection string matter in this case and what matter is how many connections you have open at the time.

you might want to step through the code and find out where the calls are being made to the db.

hi,

thanks for the response...

i double-checked my code to see if there were any connections left open.

on my login screen, my btnOK_Click contains a conn.Open. but i have a conn.Close and conn.Dispose after. then when i'm on my main screen (blank MDI Form) not doing anything, only one session is created. if i try to pull up a form with datatables, datasets, tableadapters (strong typed dataset), it creates another session.

i noticed that the session that stays is the one created on my login screen. maybe i didnt dispose of the connection correctly?
 
are you using the same connection to pull up the data on the new form or using existing connection on the login form?

im creating a new connection with same connectionstring.

VB.NET:
Dim tmpConn as New OracleConnection(My.Settings.Item("myConnectionString"))
Dim tmpComm as New OracleCommand("SELECT COUNT(1) FROM DUAL", tmpConn)
Try
tmpConn.Open()
tmpComm.ExecuteNonQuery()
tmpComm.Dispose()
tmpConn.Close()
tmpConn.Dispose()
Catch ex as Exception
tmpComm.Dispose()
tmpConn.Close()
tmpConn.Dispose()
MessageBox.Show(ex.Message)
End Try
 
connections and connectionstrings aren't the same. you can use the same connectionstring to open multiple connections.

does that mean creating new connection creates new session?
 
The connection pool regulates this, same app + same conn.string = one conn.pool, when the .Net data providers want to open a connection they ask the pool for one, if one is available it is returned else pool opens a new one. Closing a connection from the app doesn't really close the connection, it is returned to pool and marked as available. If one pool have overlapping connections in time there will be more than one open connection in pool. If you have used different conn.strings from same app you have opened more than one pool. A pool can be requested emptied by a call to ClearPool, this marks all connections in pool for disposal, and they will as soon as these connections are closed from usage, otherwise the pool is only cleared when application is closed (appdomain unloaded).
Here's an article about it: SQL Server Connection Pooling (ADO.NET)
Connection Pooling for the .NET Framework Data Provider for Oracle
 
it's called connection pooling. leave it alone and stop worrying about it :)

lolz.. i've been given the same advice on other forums.
it seems that having a few inactive sessions doesn't affect database performance that much or so they say.
 
Back
Top