Issue Details (XML | Word | Printable)

Key: DNET-398
Type: Bug Bug
Status: Resolved Resolved
Resolution: Won't Fix
Priority: Critical Critical
Assignee: Jiri Cincura
Reporter: Fernando Nájera
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
.NET Data provider

FbConnection.CreateDatabase does not always throw exceptions when it cannot create the database

Created: 17/Oct/11 09:37 AM   Updated: 06/Jul/15 07:12 AM
Component/s: ADO.NET Provider
Affects Version/s: 2.6.5, 2.7
Fix Version/s: 4.7.0.0

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


 Description  « Hide
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!

 All   Comments   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Jiri Cincura added a comment - 26/Mar/12 07:44 AM
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.

Fernando Nájera added a comment - 26/Mar/12 11:20 AM
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.

Fernando Nájera added a comment - 26/Mar/12 11:28 AM
Updated affected versions and the environment (version of Firebird *is* relevant)

Jiri Cincura added a comment - 16/Apr/12 11:28 AM - edited
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.

Jiri Cincura added a comment - 06/Jul/15 07:12 AM
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).