You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ibatis.apache.org by "M F (JIRA)" <ib...@incubator.apache.org> on 2009/07/24 16:21:15 UTC

[jira] Issue Comment Edited: (IBATISNET-291) SqlMapper.OpenConnection() does not actually open connection

    [ 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