Using transaction commands directly instead of PgSqlTransact

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for PostgreSQL
Post Reply
JORGEMAL
Posts: 168
Joined: Thu 03 Jul 2008 23:55

Using transaction commands directly instead of PgSqlTransact

Post by 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?

Respectfully,
Jorge Maldonado

Pinturiccio
Devart Team
Posts: 2192
Joined: Wed 02 Nov 2011 09:44

Post by 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: http://www.devart.com/dotconnect/postgr ... cript.html
For example you can use the following code:

Code: Select all

PgSqlConnection conn = new PgSqlConnection("Host=***;port=***;user id=***;password=***;");
            conn.Open();
            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;
commit;";
            script.Execute();
DDL/DML Scripts:

Code: Select all

CREATE TABLE dept
(
  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');

Post Reply