Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FbConnection.CreateDatabase does not always throw exceptions when it cannot create the database [DNET398] #401

Closed
firebird-automations opened this issue Oct 17, 2011 · 8 comments

Comments

@firebird-automations
Copy link

Submitted by: Fernando Nájera (fernandonajera)

Consider the following code:

string file = @"X:\Test.fdb";
File.Delete (file);

string cnnStr = @"character set=UTF8;connection lifetime=15;user id=SYSDBA;password=masterkey;initial catalog=" + file + @";data source=localhost;dialect=3;pooling=False;min pool size=0;max pool size=50;packet size=8192;server type=Default";
FbConnection.CreateDatabase (cnnStr, 8192, true, false);
FbConnection.CreateDatabase (cnnStr, 8192, true, false);

Test #⁠1: run the code as-is

In 2.6.0.0, the second CreateDatabase fails with 'I/O error during "CreateFile (create)" operation for file "X:\TEST.FDB" // Error while trying to create file', which is fine.
In 2.6.5.0, the second CreateDatabase fails with 'I/O error during "CreateFile (create)" operation for file "X:\TEST.FDB" // Error while trying to create file', which is fine.

Test #⁠2: run up to the first FbConnection, then connect to the database using another process (e.g. via isql), and while connected, run the second FbConnection

In 2.6.0.0, the second CreateDatabase fails with 'invalid database handle (no active connection)', which is good enough for me.
In 2.6.5.0, the second CreateDatabase does not throw any exception!

Test #⁠3: change the code above so instead of the two CreateDatabase calls you have now this:

FbConnection.CreateDatabase (cnnStr, 8192, true, false);
using (FbConnection cnn = new FbConnection (cnnStr))
{
cnn.Open ();
FbConnection.CreateDatabase (cnnStr, 8192, true, false);
}

In 2.6.0.0, the second CreateDatabase fails with 'invalid database handle (no active connection)', which is good enough for me.
In 2.6.5.0, the second CreateDatabase does not throw any exception!

The bottom line is, if the database has any active connection (by the same or by another process), CreateDatabase does not fail in 2.6.5.0! This is a change of behaviour against 2.6.0.0, and in my opinion is a bug - CreateDatabase should create a database, or fail.

I have put the priority to Critical, because this behavior can effectively lead to crashes - the call does not fail, so you think you have created a new, empty database, when in fact you are reusing an existing database!

@firebird-automations
Copy link
Author

Commented by: @cincuranet

I'm unable to reproduce this bug on 2.6.5 and 2.7.0. The #⁠3 throws:
"I/O error during "CreateFile (create)" operation for file "I:\Test.fdb"
Error while trying to create file"
on second FbConnection.CreateDatabase.

@firebird-automations
Copy link
Author

Modified by: @cincuranet

status: Open [ 1 ] => In Progress [ 3 ]

@firebird-automations
Copy link
Author

Commented by: Fernando Nájera (fernandonajera)

Thanks for your comment. I tried to replicate it again, and I couldn't... until I remembered that I have upgraded Firebird in my machine recently.

The error is reproducible against Firebird 2.1.4, but not against 2.5.1 (those are the two versions we use).

Test program (console):

        Console\.WriteLine \(
            typeof \(FbConnection\)\.Assembly\.FullName \+ " \- " \+
            typeof \(FbConnection\)\.Assembly\.ImageRuntimeVersion\);

        try
        \{
            string file = @"X:\\Test\.fdb";
            File\.Delete \(file\);

            string cnnStr = @"port=35000;character set=UTF8;connection lifetime=15;user id=SYSDBA;password=masterkey;initial catalog=" \+ file \+ @";data source=localhost;dialect=3;pooling=False;min pool size=0;max pool size=50;packet size=8192;server type=Default";

            FbConnection\.CreateDatabase \(cnnStr, 8192, true, false\);
            using \(FbConnection cnn = new FbConnection \(cnnStr\)\)
            \{
                cnn\.Open \(\);
                Console\.WriteLine \(cnn\.ServerVersion\);
                Console\.WriteLine \("attempt\.\.\."\);
                FbConnection\.CreateDatabase \(cnnStr, 8192, true, false\);
                Console\.WriteLine \("This should NEVER happen\!"\);
            \}
        \}
        catch \(Exception ex\)
        \{
            Console\.WriteLine \("Exception: " \+ ex\);
        \}

        Console\.ReadLine \(\);

-- Fb214 Provider 260 .NET 3.5 ---------------------------------------------
FirebirdSql.Data.FirebirdClient, Version=2.6.0.0, Culture=neutral, PublicKeyToken=3750abcc3150b00c - v2.0.50727
WI-V2.1.4.18393 Firebird 2.1
attempt...
Exception: FirebirdSql.Data.FirebirdClient.FbException (0x80004005): invalid database handle (no active connection) --->
invalid database handle (no active connection)
at FirebirdSql.Data.FirebirdClient.FbConnection.CreateDatabase(String connectionString, Int32 pageSize, Boolean force
dWrites, Boolean overwrite) in C:\Users\Jiri\Desktop\NETProvider\source\FirebirdSql\Data\FirebirdClient\FbConnection.cs:
line 138
at WindowsFormsApplication1.Program.Main()
-- Fb214 Provider 260 .NET 4.0 ---------------------------------------------
FirebirdSql.Data.FirebirdClient, Version=2.6.0.0, Culture=neutral, PublicKeyToken=3750abcc3150b00c - v4.0.30319
WI-V2.1.4.18393 Firebird 2.1
attempt...
Exception: FirebirdSql.Data.FirebirdClient.FbException (0x80004005): invalid database handle (no active connection) --->
invalid database handle (no active connection)
at FirebirdSql.Data.FirebirdClient.FbConnection.CreateDatabase(String connectionString, Int32 pageSize, Boolean force
dWrites, Boolean overwrite) in C:\Users\Jiri\Desktop\NETProvider\source\FirebirdSql\Data\FirebirdClient\FbConnection.cs:
line 138
at WindowsFormsApplication1.Program.Main()
-- Fb214 Provider 265 .NET 3.5 ---------------------------------------------
FirebirdSql.Data.FirebirdClient, Version=2.6.5.0, Culture=neutral, PublicKeyToken=3750abcc3150b00c - v2.0.50727
WI-V2.1.4.18393 Firebird 2.1
attempt...
This should NEVER happen!
-- Fb214 Provider 265 .NET 4.0 ---------------------------------------------
FirebirdSql.Data.FirebirdClient, Version=2.6.5.0, Culture=neutral, PublicKeyToken=3750abcc3150b00c - v4.0.30319
WI-V2.1.4.18393 Firebird 2.1
attempt...
This should NEVER happen!
-- Fb214 Provider 270 .NET 3.5 ---------------------------------------------
FirebirdSql.Data.FirebirdClient, Version=2.7.0.0, Culture=neutral, PublicKeyToken=3750abcc3150b00c - v2.0.50727
WI-V2.1.4.18393 Firebird 2.1
attempt...
This should NEVER happen!
-- Fb214 Provider 270 .NET 4.0 ---------------------------------------------
FirebirdSql.Data.FirebirdClient, Version=2.7.0.0, Culture=neutral, PublicKeyToken=3750abcc3150b00c - v4.0.30319
WI-V2.1.4.18393 Firebird 2.1
attempt...
This should NEVER happen!
---------------------------------------------

Tests with Firebird 2.5.1

-- Fb251 Provider 260 .NET 3.5 ---------------------------------------------
FirebirdSql.Data.FirebirdClient, Version=2.6.0.0, Culture=neutral, PublicKeyToken=3750abcc3150b00c - v2.0.50727
WI-V2.5.1.26351 Firebird 2.5
attempt...
Exception: FirebirdSql.Data.FirebirdClient.FbException (0x80004005): unsuccessful metadata update
object DATABASE is in use ---> unsuccessful metadata update
object DATABASE is in use
at FirebirdSql.Data.FirebirdClient.FbConnection.CreateDatabase(String connectionString, Int32 pageSize, Boolean force
dWrites, Boolean overwrite) in C:\Users\Jiri\Desktop\NETProvider\source\FirebirdSql\Data\FirebirdClient\FbConnection.cs:
line 138
at WindowsFormsApplication1.Program.Main()
-- Fb251 Provider 260 .NET 4.0 ---------------------------------------------
FirebirdSql.Data.FirebirdClient, Version=2.6.0.0, Culture=neutral, PublicKeyToken=3750abcc3150b00c - v4.0.30319
WI-V2.5.1.26351 Firebird 2.5
attempt...
Exception: FirebirdSql.Data.FirebirdClient.FbException (0x80004005): unsuccessful metadata update
object DATABASE is in use ---> unsuccessful metadata update
object DATABASE is in use
at FirebirdSql.Data.FirebirdClient.FbConnection.CreateDatabase(String connectionString, Int32 pageSize, Boolean force
dWrites, Boolean overwrite) in C:\Users\Jiri\Desktop\NETProvider\source\FirebirdSql\Data\FirebirdClient\FbConnection.cs:
line 138
at WindowsFormsApplication1.Program.Main()
-- Fb251 Provider 265 .NET 3.5 ---------------------------------------------
FirebirdSql.Data.FirebirdClient, Version=2.6.5.0, Culture=neutral, PublicKeyToken=3750abcc3150b00c - v2.0.50727
WI-V2.5.1.26351 Firebird 2.5
attempt...
Exception: FirebirdSql.Data.FirebirdClient.FbException (0x80004005): unsuccessful metadata update
object DATABASE is in use ---> unsuccessful metadata update
object DATABASE is in use
at FirebirdSql.Data.FirebirdClient.FbConnection.CreateDatabase(String connectionString, Int32 pageSize, Boolean force
dWrites, Boolean overwrite) in C:\Users\Jiri\Desktop\NETProvider\source\FirebirdSql\Data\FirebirdClient\FbConnection.cs:
line 138
at WindowsFormsApplication1.Program.Main()
-- Fb251 Provider 265 .NET 4.0 ---------------------------------------------
FirebirdSql.Data.FirebirdClient, Version=2.6.5.0, Culture=neutral, PublicKeyToken=3750abcc3150b00c - v4.0.30319
WI-V2.5.1.26351 Firebird 2.5
attempt...
Exception: FirebirdSql.Data.FirebirdClient.FbException (0x80004005): unsuccessful metadata update
object DATABASE is in use ---> unsuccessful metadata update
object DATABASE is in use
at FirebirdSql.Data.FirebirdClient.FbConnection.CreateDatabase(String connectionString, Int32 pageSize, Boolean force
dWrites, Boolean overwrite) in C:\Users\Jiri\Desktop\NETProvider\source\FirebirdSql\Data\FirebirdClient\FbConnection.cs:
line 138
at WindowsFormsApplication1.Program.Main()
-- Fb251 Provider 270 .NET 3.5 ---------------------------------------------
FirebirdSql.Data.FirebirdClient, Version=2.7.0.0, Culture=neutral, PublicKeyToken=3750abcc3150b00c - v2.0.50727
WI-V2.5.1.26351 Firebird 2.5
attempt...
Exception: FirebirdSql.Data.FirebirdClient.FbException (0x80004005): unsuccessful metadata update
object DATABASE is in use ---> unsuccessful metadata update
object DATABASE is in use
at FirebirdSql.Data.FirebirdClient.FbConnection.CreateDatabase(String connectionString, Int32 pageSize, Boolean force
dWrites, Boolean overwrite) in C:\Users\Jiri\Desktop\NETProvider\source\FirebirdSql\Data\FirebirdClient\FbConnection.cs:
line 138
at WindowsFormsApplication1.Program.Main()
-- Fb251 Provider 270 .NET 4.0 ---------------------------------------------
FirebirdSql.Data.FirebirdClient, Version=2.7.0.0, Culture=neutral, PublicKeyToken=3750abcc3150b00c - v4.0.30319
WI-V2.5.1.26351 Firebird 2.5
attempt...
Exception: FirebirdSql.Data.FirebirdClient.FbException (0x80004005): unsuccessful metadata update
object DATABASE is in use ---> unsuccessful metadata update
object DATABASE is in use
at FirebirdSql.Data.FirebirdClient.FbConnection.CreateDatabase(String connectionString, Int32 pageSize, Boolean force
dWrites, Boolean overwrite) in C:\Users\Jiri\Desktop\NETProvider\source\FirebirdSql\Data\FirebirdClient\FbConnection.cs:
line 138
at WindowsFormsApplication1.Program.Main()
---------------------------------------------

As we have users that might be using the old version of Firebird (2.1.x), we need to ensure that our code works as expected with them. Interestingly, as you can see, 2.6.0 did work in all the situations; but 2.6.5 and 2.7.0 don't.

@firebird-automations
Copy link
Author

Commented by: Fernando Nájera (fernandonajera)

Updated affected versions and the environment (version of Firebird *is* relevant)

@firebird-automations
Copy link
Author

Modified by: Fernando Nájera (fernandonajera)

Version: 2.7 [ 10431 ]

environment: Tested against Firebird 2.1.4; apparently it works if used against Firebird 2.5.1

@firebird-automations
Copy link
Author

Commented by: @cincuranet

Same on 2.1.3. But even if I force provider to take exactly same code path for 2.1 as for 2.5 the behavior differs (on 2.7.5 provider).

BTW the "invalid database handle (no active connection)" is just a side-effect of already fixed bug. The exception should be same.

@firebird-automations
Copy link
Author

Commented by: @cincuranet

Looks like the Firebird 2.1.x doesn't return the error. I just get a valid response, without any exception. I asked CORE devs, but no reply. Probably just an improvement in 2.5.x and nobody remembers.

The "invalid database handle (no active connection)" that was there was a bug in my code. It looked like it is working, but it was failing (but for another reason).

@firebird-automations
Copy link
Author

Modified by: @cincuranet

status: In Progress [ 3 ] => Resolved [ 5 ]

resolution: Won't Fix [ 2 ]

Fix Version: vNext [ 10704 ]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants