internal Boolean IsValid()
{
try
{
// Here we use a fake NpgsqlCommand, just to send the test query string.
// Get random test value.
Byte[] testBytes = new Byte[2];
rng.GetNonZeroBytes(testBytes);
String testValue = String.Format("Npgsql{0}{1}", testBytes[0], testBytes[1]);
//Query(new NpgsqlCommand("select 1 as ConnectionTest", this));
string compareValue = string.Empty;
string sql = "select '" + testValue + "'";
// restore initial connection parameters resetted by "Discard ALL"
if (SupportsDiscard)
{
sql = this.initQueries + sql;
}
using(NpgsqlCommand cmd = new NpgsqlCommand(sql, this))
{
compareValue = (string) cmd.ExecuteScalar();
}
if (compareValue != testValue)
{
return false;
}
this.RequireReadyForQuery = true;
}
catch
{
return false;
}
return true;
}