The exception that is generated when PostgreSQL returns a warning or error.
The following example generates a
PgSqlException due to a missing database, and then displays the exception.
public void ThrowPgSqlException()
{
string mySelectQuery = "SELECT * FROM Test.Dept";
PgSqlConnection myConnection =
new PgSqlConnection("host=server;database=test;user id=postgres");
PgSqlCommand myCommand = new PgSqlCommand(mySelectQuery,myConnection);
try
{
myCommand.Connection.Open();
}
catch (PgSqlException myException)
{
MessageBox.Show("Message: " + myException.Message + "\n");
}
}
Public Sub ThrowPgSqlException()
Dim mySelectQuery As String = "SELECT * FROM Test.Dept"
Dim myConnection As New PgSqlConnection _
("host=server;database=test;user id=postgres")
Dim myCommand As New PgSqlCommand(mySelectQuery, myConnection)
Try
myCommand.Connection.Open()
Catch myException As PgSqlException
MessageBox.Show("Message: " + myException.Message + ControlChars.Cr)
End Try
End Sub
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2