How to get an exclusive firebird database lock to perform schema changes?

To be more specific, I use firebird 2.1 and the DDEX provider for visual studio, and I work in C #.

I have a situation where I try to apply schema changes to a database from C # in order to “update” my database. During this process, I get the following exception from firebird:

FirebirdSql.Data.FirebirdClient.FbException: unsuccessful INDEX metadata update object used

I interpreted this as a problem of consistency when there is another processuality that accesses the database at the same time. I do not know that this is the reason for the certian, but it "seems" to be the most likely case. I thought that this could be due to the removal and addition of restrictions, since they are not additional, because the restriction is incorrect, but I can run commands on my local system without errors, and not on the client site. Anyway, currently I have several commands wrapped in a single transaction using the isolation level of “Serializable” and commit them all at once. Since this is an update, the thinking is that it can block all other users as needed.

Example:

// note connection is pre-defined as a FbConnection, connected to the Database in question

FbTransaction transaction = Connection.BeginTransaction( IsolationLevel.Serializable );

// quite a bit of stuff gets done here, this is a sample
// I can run all the commands in this section in the isql tool and commit them all at once
// without error.  NOTE: I have not tried to run them all on the client enviroment, and likely can't

string commandString = "ALTER TABLE Product DROP CONSTRAINT ProductType;";
FbCommand command = new FbCommand(commandString, Connection, transaction);
command.ExecuteNonQuery();

commandString = "ALTER TABLE Product ADD CONSTRAINT ProductType " +
                "FOREIGN KEY ( TypeID ) REFERENCES Type ( TypeID ) " +
                "ON UPDATE CASCADE ON DELETE NO ACTION;";
command.CommandText = commandString;
command.ExecuteNonQuery();

// other commands include: 
// creating a new table
// creating 3 triggers for the new table

// commit the transaction
// this particular line actually "seems" to throw the exception mentioned

transaction.Commit();

, "" , , , , , , .

:

// Try to use FbTransactionOptions instead
// this statement complains about invalid options block when executing
FbTransaction transaction = Connection.BeginTransaction(
            FbTransactionOptions.Consistency |
            FbTransactionOptions.Exclusive |
            FbTransactionOptions.Wait |
            FbTransactionOptions.Write |
            FbTransactionOptions.LockWrite |
            FbTransactionOptions.NoRecVersion
            );

, : db ? , . !!!


: , :

FirebirdSql.Data.FirebirdClient.FbException: FOREIGN KEY "INTEG_72" ""

, .


, . , , :

FirebirdSql.Data.FirebirdClient.FbException: INDEX

:

FirebirdSql.Data.FirebirdClient.FbException: FOREIGN KEY "INTEG_72" ""

. , , . - , , .


. jachguate, , .

+3
2

, gfix ( # , , script, ).

, , . Firebird, , . :
gfix -shut OPTION TIMEOUT database_name
TIMEOUT - , . , . , , . OPTION : * -at [tach] - . * -tr [an] - . * -f [orce] - . , SYSDBA .

firebird 2.0, state :

gfix -shut single -force 60 mydatabase.fdb

60 , sysdba .

+2
-4

Source: https://habr.com/ru/post/1792353/


All Articles