When a value is assigned to this property, the PgSqlConnection is closed.
public void UploadString(PgSqlConnection pgConnection) { pgConnection.Unicode = true; PgSqlCommand pgCommand = new PgSqlCommand("INSERT INTO Test.TextBlocks (BlockID, BlockName, BlockContent) VALUES(1,'First',:BlockText)", pgConnection); pgCommand.Parameters.Add("BlockText",PgSqlType.VarChar,50).Value = "Place here some text that requires Unicode support."; pgConnection.Open(); try { Console.WriteLine(pgCommand.ExecuteNonQuery()+" rows affected."); } finally { pgConnection.Close(); } } public void DownloadString(PgSqlConnection pgConnection) { pgConnection.Unicode = true; PgSqlCommand pgCommand = new PgSqlCommand("SELECT * FROM Test.TextBlocks", pgConnection); pgConnection.Open(); PgSqlDataReader pgReader = pgCommand.ExecuteReader(CommandBehavior.Default); try { while (pgReader.Read()) { string myString = (string)pgReader["BlockContent"]; Console.WriteLine(myString); } } finally { pgReader.Close(); pgConnection.Close(); } }
Public Sub UploadString(ByVal pgConnection As PgSqlConnection) pgConnection.Unicode = True Dim pgCommand As New PgSqlCommand("INSERT INTO Test.TextBlocks (BlockID, BlockName, BlockContent) VALUES(1,'First',:BlockText)", pgConnection) pgCommand.Parameters.Add("BlockText", PgSqlType.VarChar, 50).Value = "Place here some text that requires Unicode support." pgConnection.Open() Try Console.WriteLine(String.Concat(pgCommand.ExecuteNonQuery(), " rows affected.")) Finally pgConnection.Close() End Try End Sub Public Sub DownloadString(ByVal pgConnection As PgSqlConnection) pgConnection.Unicode = True Dim pgCommand As New PgSqlCommand("SELECT * FROM Test.TextBlocks", pgConnection) pgConnection.Open() Dim pgReader As PgSqlDataReader = pgCommand.ExecuteReader(CommandBehavior.Default) Try While pgReader.Read() Dim myString As String = CType(pgReader("BlockContent"), String) Console.WriteLine(myString) End While Finally pgReader.Close() pgConnection.Close() End Try End Sub