Description
If you post yours SqlDataAdapter, it will not delete SqlConnection, because it is unclear whether you want to use the connection again. You must change your design to do this.
I suggest passing SqlConnectionfunctions GetDataAdapter.
Example
static void Main(string[] args)
{
using (SqlConnection connection = GetConnection())
{
using (SqlDataAdapter adapter = GetDataAdapter("YourQuery", connection))
{
}
}
}
private static readonly string ConnectionString = "Dummy";
public static SqlConnection GetConnection()
{
SqlConnection Connection = new SqlConnection(ConnectionString);
return Connection;
}
public static SqlDataAdapter GetDataAdapter(string Query, SqlConnection connection)
{
SqlDataAdapter Adapt = new SqlDataAdapter(Query, connection);
return Adapt;
}
source
share