I am using ODBC to connect to a Sybase databse. The problem is the connection doesn’t close even after it’s is scope complete, and I see around 200 connection open in the database when I run sp_who. I tried enabling the connection pool, but that doesn’t help either.
using(var connection = GetOdbcConnection())
{
connection.Open();
using (var cmd = new OdbcCommand(query, connection))
{
var reader = cmd.ExecuteReader();
if (reader.Read())
{
long textLen = reader.GetChars(0, 0, null, 0, 0);
}
reader.Close();
}
}
The connection string which I use is value="Driver={Adaptive Server Enterprise};app=xxx;server=xxxx;port=xxxx; db=xxx;uid=xxx;pwd=xxxx;textsize=2097152".
Update:
public static OdbcConnection GetOdbcConnection() {
string connectionString = ConfigurationManager.AppSettings["ConnectionString"].ToString();
return new OdbcConnection(connectionString);
}
Have you tried
connection.Close()?