ibatis-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jonas Hamnered (JIRA)" <ibatis-...@incubator.apache.org>
Subject [jira] Created: (IBATISNET-291) SqlMapper.OpenConnection() does not actually open connection
Date Thu, 02 Apr 2009 14:05:13 GMT
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

        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

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)

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.

View raw message