Using transaction commands directly instead of PgSqlTransact

Using transaction commands directly instead of PgSqlTransact

Postby JORGEMAL » Tue 31 Jan 2012 16:05

Talking about transactions, is it possible to issue BEGIN, COMMIT, ROLLBACK commands instead of using PgSqlTransaction?

If so, what would be the advantage/disadvantage of issuing transaction command directly?

Jorge Maldonado
Posts: 164
Joined: Thu 03 Jul 2008 23:55

Postby Pinturiccio » Thu 02 Feb 2012 08:55

Yes, you can. You can use PgSqlScript, which allows you to execute several SQL statements one by one, for this. For more information please refer to: ... cript.html
For example you can use the following code:
Code: Select all
PgSqlConnection conn = new PgSqlConnection("Host=***;port=***;user id=***;password=***;");
            PgSqlScript script = new PgSqlScript();
            script.Connection = conn;
            script.ScriptText = @"begin;
select * from dept where deptno=212;
update dept set loc='NY' where deptno=212;
select * from dept where deptno=212;

DDL/DML Scripts:
Code: Select all
  deptno integer NOT NULL,
  dname character varying(14),
  loc character varying(13),
  CONSTRAINT dept_pkey PRIMARY KEY (deptno)

INSERT INTO dept(deptno, dname, loc)
    VALUES (212, 'Butcher', 'Vegas');
Devart Team
Posts: 1982
Joined: Wed 02 Nov 2011 09:44

Return to dotConnect for PostgreSQL