Hey,
I've got a spec project setup that I'm trying to use a SQLite database with. Only I'm having a problem "Session was closed" even when the session appears to only just been created.
First of all in my specs folder I have this configuration:
<activeRecord isWeb="true" threadinfotype="Orange.TicketManager.Specs.Config.HybridWebThreadScopeInfo, Orange.TicketManager.Specs">
<config>
<add key="connection.driver_class" value="NHibernate.Driver.SQLite20Driver" />
<add key="connection.provider"
value="MyProject.SQLiteInMemoryTestingConnectionProvider, myProject" />
<add key="dialect" value="NHibernate.Dialect.SQLiteDialect" />
<add key="proxyfactory.factory_class" value="NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle" />
<add key="connection.connection_string" value="Data Source=:memory:;Version=3;New=True;" />
<add key="hibernate.query.substitutions" value="true=1false=0" />
</config>
</activeRecord>
Which points it to these classes:
public class HybridWebThreadScopeInfo : AbstractThreadScopeInfo, IWebThreadScopeInfo
{
const string ActiveRecordCurrentStack = "activerecord.currentstack";
[ThreadStatic]
static Stack stack;
/// <summary>
/// Gets the current stack.
/// </summary>
/// <value>The current stack.</value>
public override Stack CurrentStack
{
[MethodImpl(MethodImplOptions.Synchronized)]
get
{
HttpContext current = HttpContext.Current;
if (current == null)
{
if (stack == null)
{
stack = new Stack();
}
return stack;
}
Stack contextstack = (Stack)current.Items[ActiveRecordCurrentStack];
if (contextstack == null)
{
contextstack = new Stack();
current.Items[ActiveRecordCurrentStack] = contextstack;
}
return contextstack;
}
}
}
public class SQLiteInMemoryTestingConnectionProvider : NHibernate.Connection.DriverConnectionProvider
{
public static System.Data.IDbConnection Connection = null;
public override System.Data.IDbConnection GetConnection()
{
if (Connection == null)
Connection = base.GetConnection();
return Connection;
}
public override void CloseConnection(System.Data.IDbConnection conn) { }
}
I've debugged to ensure that both of these classes are being used; they definitely are.
In my step file (I'm using SpecFlow) I initialise and create the schema for Active record. Create a repository and add records to the repository.
When I add the records I don't get any errors. However, when I 'enumerate over the results'' I see "Session is closed" object: "ISession".
when I then try to query my repository, there are no results.
Any suggestions? Unfortunately the Castle forums are down at the moment so please help me.