Create Database error - cannot run inside a transaction block

The forum for ZeosLib 7.2 Report problems. Ask for help, post proposals for the new version and Zeoslib 7.2 features here. This is a forum that will be edited once the 7.2.x version goes into RC/stable!!

My personal intention for 7.2 is to speed up the internals as optimal a possible for all IDE's. Hope you can help?! Have fun with testing 7.2
Post Reply
gustavototta
Fresh Boarder
Fresh Boarder
Posts: 9
Joined: 02.02.2023, 20:28

Create Database error - cannot run inside a transaction block

Post by gustavototta »

Hi everyone!

Can anyone help with this question?

Zeos version: 7.2.14-release
Delphi Version: 10 - Seattle
Postgresql Version: 9.3

I'm trying create database with Zeos on runtime with ZSQLProcessor, but i receive this error:
CREATE DATABASE cannot run inside a transaction block

My script create database:

Code: Select all

    ZSQLProcessor := TZSQLProcessor.Create(Self);
    ZSQLProcessor.Connection := ConexaoLog;

    script := 'CREATE DATABASE imagem '+
              'WITH OWNER = postgres '+
              'TABLESPACE = pg_default '+
              'LC_COLLATE = ''Portuguese_Brazil.1252'' '+
              'LC_CTYPE = ''Portuguese_Brazil.1252'' '+
              'CONNECTION LIMIT = -1;';

    ZSQLProcessor.Script.Text := script;
    ZSQLProcessor.Execute;
    ZSQLProcessor.free;
Observation: In another topic, an user say to change the property "TransactIsolationLevel" to "tiNone", but doesn't work for me.
(because see in the image that I'm already passing it as itNone)
Image

Thank you so much! Hugs
marsupilami
Platinum Boarder
Platinum Boarder
Posts: 1928
Joined: 17.01.2011, 14:17

Re: Create Database error - cannot run inside a transaction block

Post by marsupilami »

I am not sure if TZSQLProcessor starts a transaction automatically. Is AutoCommit set to true on your connection?
Since the create database statement really is only one statement, you don't need to use TZSQLProcessor. What happens, if you do something like the follwing code block?

Code: Select all

    script := 'CREATE DATABASE imagem '+
              'WITH OWNER = postgres '+
              'TABLESPACE = pg_default '+
              'LC_COLLATE = ''Portuguese_Brazil.1252'' '+
              'LC_CTYPE = ''Portuguese_Brazil.1252'' '+
              'CONNECTION LIMIT = -1;';
    ConexaoLog.ExecuteDirect(script);
gustavototta
Fresh Boarder
Fresh Boarder
Posts: 9
Joined: 02.02.2023, 20:28

Re: Create Database error - cannot run inside a transaction block

Post by gustavototta »

Hello, how are you?

The resolution for the problem:
ConexaoLog.AutoCommit := true;

its works! :)

Thanks so much
Post Reply