You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ibatis.apache.org by "Jonas Hamnered (JIRA)" <ib...@incubator.apache.org> on 2009/04/02 16:05:13 UTC
[jira] Created: (IBATISNET-291) SqlMapper.OpenConnection() does not
actually open connection
SqlMapper.OpenConnection() does not actually open connection
------------------------------------------------------------
Key: IBATISNET-291
URL: https://issues.apache.org/jira/browse/IBATISNET-291
Project: iBatis for .NET
Issue Type: Bug
Components: DataAccess
Affects Versions: DataAccess 1.9 .1
Reporter: Jonas Hamnered
The second sqlMap.OpenConnection() in the following sample causes an exception for DataAccess 1.9.1.
ISqlMapper sqlMap = Mapper.Get();
using (IDalSession session = sqlMap.OpenConnection())
{
// session for some reason never used, could be due to logic in called methods
}
using (IDalSession session = sqlMap.OpenConnection())
{
}
The exception is:
IBatisNet.DataMapper.Exceptions.DataMapperException: SqlMap could not invoke OpenConnection(). A connection is already started. Call CloseConnection first.
at IBatisNet.DataMapper.SqlMapper.OpenConnection() in C:\Devel\lib\iBatis\IBatisNet.DataMapper\SqlMapper.cs:line 204
The reason is as far as I can tell that sqlMap.OpenConnection no longer opens the underlying connection. Instead this is done "on demand".
The problem is that if the session is never used before being disposed, SqlMapSession.Dispose() does not properly cause the SqlMapper._sessionStore.Dispose() to be called:
[from IBatisNet.DataMapper.SqlMapSession.Dispose()]
if (_isTransactionOpen == false)
{
if (_connection.State != ConnectionState.Closed)
{
_sqlMapper.CloseConnection();
}
}
This finally causes the second sqlMap.OpenConnection() call to throw an exception since the
[from IBatisNet.DataMapper.SqlMapper]
public ISqlMapSession OpenConnection()
{
if (_sessionStore.LocalSession != null)
{
throw new DataMapperException("SqlMap could not invoke OpenConnection(). A connection is already started. Call CloseConnection first.");
}
...
A possible work-around is to manually call session.OpenConnection() inside the using block.
Possible fixes could obviously be:
* to make sqlMap.OpenConnection always open the db connection (like in earlier versions, and as the name says)
* alter SqlMapSession.Dispose() to somehow cause a SqlMapper._sessionStore.Dispose() even if the connection is closed
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Issue Comment Edited: (IBATISNET-291)
SqlMapper.OpenConnection() does not actually open connection
Posted by "M F (JIRA)" <ib...@incubator.apache.org>.
[ https://issues.apache.org/jira/browse/IBATISNET-291?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12735062#action_12735062 ]
M F edited comment on IBATISNET-291 at 7/24/09 7:20 AM:
--------------------------------------------------------
Here's a hastily hacked patch I made for the revision 709676 source.
(Resulting DLL also attached.)
I implemented the submitter's idea of having SqlMapSession.Dispose() call SqlMapper._sessionStore.Dispose() when the connection is closed:
if (_isTransactionOpen == false)
{
if (_connection.State != ConnectionState.Closed)
{
_sqlMapper.CloseConnection();
}
else
{
_sqlMapper.SessionStore.Dispose();
}
}
Note that this also involved adding a public getter for SessionStore.
If anyone encounters problems with this, please comment about it.
was (Author: maf7777):
Here's a hastily hacked patch I made for the revision 709676 source.
(Resulting DLL also attached.)
I implemented the submitter's idea of having SqlMapSession.Dispose() call SqlMapper._sessionStore.Dispose() when the connection is closed:
if (_isTransactionOpen == false)
{
if (_connection.State != ConnectionState.Closed)
{
_sqlMapper.CloseConnection();
}
else
{
_sqlMapper.SessionStore.Dispose();
}
}
Note that this also involved adding a public getter for SessionStore.
If anyone encounters problems with this, please comment about it.
> SqlMapper.OpenConnection() does not actually open connection
> ------------------------------------------------------------
>
> Key: IBATISNET-291
> URL: https://issues.apache.org/jira/browse/IBATISNET-291
> Project: iBatis for .NET
> Issue Type: Bug
> Components: DataMapper
> Affects Versions: DataMapper 1.6.1
> Reporter: Jonas Hamnered
> Attachments: IBATISNET-291_session-dispose.patch, IBatisNet.DataMapper_patched.dll
>
>
> The second sqlMap.OpenConnection() in the following sample causes an exception for DataMapper 1.6.1.
> ISqlMapper sqlMap = Mapper.Get();
> using (IDalSession session = sqlMap.OpenConnection())
> {
> // session for some reason never used, could be due to logic in called methods
> }
> using (IDalSession session = sqlMap.OpenConnection())
> {
> }
> The exception is:
> IBatisNet.DataMapper.Exceptions.DataMapperException: SqlMap could not invoke OpenConnection(). A connection is already started. Call CloseConnection first.
> at IBatisNet.DataMapper.SqlMapper.OpenConnection() in C:\Devel\lib\iBatis\IBatisNet.DataMapper\SqlMapper.cs:line 204
> The reason is as far as I can tell that sqlMap.OpenConnection no longer opens the underlying connection. Instead this is done "on demand".
> The problem is that if the session is never used before being disposed, SqlMapSession.Dispose() does not properly cause the SqlMapper._sessionStore.Dispose() to be called:
> [from IBatisNet.DataMapper.SqlMapSession.Dispose()]
> if (_isTransactionOpen == false)
> {
> if (_connection.State != ConnectionState.Closed)
> {
> _sqlMapper.CloseConnection();
> }
> }
> This finally causes the second sqlMap.OpenConnection() call to throw an exception since the
> [from IBatisNet.DataMapper.SqlMapper]
> public ISqlMapSession OpenConnection()
> {
> if (_sessionStore.LocalSession != null)
> {
> throw new DataMapperException("SqlMap could not invoke OpenConnection(). A connection is already started. Call CloseConnection first.");
> }
> ...
> A possible work-around is to manually call session.OpenConnection() inside the using block.
> Possible fixes could obviously be:
> * to make sqlMap.OpenConnection always open the db connection (like in earlier versions, and as the name says)
> * alter SqlMapSession.Dispose() to somehow cause a SqlMapper._sessionStore.Dispose() even if the connection is closed
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ibatis.apache.org
For additional commands, e-mail: dev-help@ibatis.apache.org
[jira] Commented: (IBATISNET-291) SqlMapper.OpenConnection() does
not actually open connection
Posted by "Michael Fulker (JIRA)" <ib...@incubator.apache.org>.
[ https://issues.apache.org/jira/browse/IBATISNET-291?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12734668#action_12734668 ]
Michael Fulker commented on IBATISNET-291:
------------------------------------------
I'm getting the exception when I enable caching.
I suspect it's the same issue: cache hits prevent the connection from being used and therefore prevents Dispose() from being called properly.
> SqlMapper.OpenConnection() does not actually open connection
> ------------------------------------------------------------
>
> Key: IBATISNET-291
> URL: https://issues.apache.org/jira/browse/IBATISNET-291
> Project: iBatis for .NET
> Issue Type: Bug
> Components: DataMapper
> Affects Versions: DataMapper 1.6.1
> Reporter: Jonas Hamnered
>
> The second sqlMap.OpenConnection() in the following sample causes an exception for DataMapper 1.6.1.
> ISqlMapper sqlMap = Mapper.Get();
> using (IDalSession session = sqlMap.OpenConnection())
> {
> // session for some reason never used, could be due to logic in called methods
> }
> using (IDalSession session = sqlMap.OpenConnection())
> {
> }
> The exception is:
> IBatisNet.DataMapper.Exceptions.DataMapperException: SqlMap could not invoke OpenConnection(). A connection is already started. Call CloseConnection first.
> at IBatisNet.DataMapper.SqlMapper.OpenConnection() in C:\Devel\lib\iBatis\IBatisNet.DataMapper\SqlMapper.cs:line 204
> The reason is as far as I can tell that sqlMap.OpenConnection no longer opens the underlying connection. Instead this is done "on demand".
> The problem is that if the session is never used before being disposed, SqlMapSession.Dispose() does not properly cause the SqlMapper._sessionStore.Dispose() to be called:
> [from IBatisNet.DataMapper.SqlMapSession.Dispose()]
> if (_isTransactionOpen == false)
> {
> if (_connection.State != ConnectionState.Closed)
> {
> _sqlMapper.CloseConnection();
> }
> }
> This finally causes the second sqlMap.OpenConnection() call to throw an exception since the
> [from IBatisNet.DataMapper.SqlMapper]
> public ISqlMapSession OpenConnection()
> {
> if (_sessionStore.LocalSession != null)
> {
> throw new DataMapperException("SqlMap could not invoke OpenConnection(). A connection is already started. Call CloseConnection first.");
> }
> ...
> A possible work-around is to manually call session.OpenConnection() inside the using block.
> Possible fixes could obviously be:
> * to make sqlMap.OpenConnection always open the db connection (like in earlier versions, and as the name says)
> * alter SqlMapSession.Dispose() to somehow cause a SqlMapper._sessionStore.Dispose() even if the connection is closed
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ibatis.apache.org
For additional commands, e-mail: dev-help@ibatis.apache.org