Closed asherber closed 11 months ago
It looks like LinqPAD behavior to me.
All we do is create and return connection instance to LinqPAD here
I've made some tests:
Connection.GetHashCode().Dump();
Connection.State.Dump();
Connection.Close();
Connection.State.Dump();
Connection.GetHashCode().Dump();
54897010
Open
Open
54897010
if I save connection to variable to avoid Connection property access I get expected behavior:
var cn = Connection;
cn.GetHashCode().Dump();
cn.State.Dump();
cn.Close();
cn.State.Dump();
cn.GetHashCode().Dump();
21201098
Open
Closed
21201098
I suspect Connection property implementation by LinqPAD opens connection if it is not opened on invoke. I would recommend to ask on LinqPAD forum if it is an issue for you as I don't see currently how we can affect this behavior from driver
Thanks, that's interesting. I assumed it was a driver issue because the behavior is different if I use the LINQ to SQL driver to connect SQL Server, or if I use Npgsql directly.
Using the default LINQ to SQL driver for Sql Server, the
Connection
object in a LinqPad script starts out in a closed state and can be opened and closed as needed. But using the Linq2db driver (for a Postgres database),Connection
starts out in an open state -- and it appears that callingClose()
has no effect.Is there a way to either get the connection to start closed, or to close it by hand?