1

I am trying to connect and read data from Firebird database using the FirebirdSQL .net provider (using FirebirdSql.Data.FirebirdClient). Here is the code:

FbConnection viewdataConnection=new FbConnection();
viewdataConnection.ConnectionString = "database=localhost:c:\\firebirdTest\\testDB.fdb;user=sysdba;password=firebird";
viewdataConnection.Open();

While trying to Open() the connection, i get an error:

An unhandled exception of type 'FirebirdSql.Data.FirebirdClient.FbException' occurred in FirebirdSql.Data.FirebirdClient.dll
Additional information: Error occurred during login, please check server firebird.log for details

Here is the exception detail:

FirebirdSql.Data.FirebirdClient.FbException was unhandled
  ErrorCode=335545106
  HResult=-2147467259
  Message=Error occurred during login, please check server firebird.log for details
  SQLSTATE=08006
  Source=FirebirdSql.Data.FirebirdClient
  StackTrace:
       at FirebirdSql.Data.FirebirdClient.FbConnectionInternal.Connect()
       at FirebirdSql.Data.FirebirdClient.FbConnectionPoolManager.Pool.CreateNewConnectionIfPossibleImpl(FbConnectionString connectionString)
       at FirebirdSql.Data.FirebirdClient.FbConnectionPoolManager.Pool.GetConnection(FbConnection owner)
       at FirebirdSql.Data.FirebirdClient.FbConnection.Open()
       at UsingFirebird.FormUsers.FormUsersLoad(Object sender, EventArgs e) in C:\Users\vikas\Downloads\UsingFirebird\UsingFirebird\UsingFirebird\FormUsers.cs:line 46
       at System.Windows.Forms.Form.OnLoad(EventArgs e)
       at System.Windows.Forms.Form.OnCreateControl()
       at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
       at System.Windows.Forms.Control.CreateControl()
       at System.Windows.Forms.Control.WmShowWindow(Message& m)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.Form.WmShowWindow(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
  InnerException: 
       ErrorCode=335545106
       HResult=-2146233088
       IsWarning=false
       Message=Error occurred during login, please check server firebird.log for details
       SQLSTATE=08006
       Source=FirebirdSql.Data.FirebirdClient
       StackTrace:
            at FirebirdSql.Data.Client.Managed.GdsConnection.Identify(String database)
            at FirebirdSql.Data.FirebirdClient.ClientFactory.CreateManagedDatabase(FbConnectionString options)
            at FirebirdSql.Data.FirebirdClient.ClientFactory.CreateDatabase(FbConnectionString options)
            at FirebirdSql.Data.FirebirdClient.FbConnectionInternal.Connect()
       InnerException: 

Please help.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Vikas Kottari
  • 495
  • 2
  • 10
  • 24
  • What is the error in the `firebird.log` of the server? – Mark Rotteveel Jul 09 '19 at 06:29
  • @MarkRotteveel I'm unable to find the firebird.log file. – Vikas Kottari Jul 09 '19 at 06:31
  • It is - normally - in the root directory of your Firebird server install – Mark Rotteveel Jul 09 '19 at 06:33
  • @MarkRotteveel there is no such file in the root directory, I have also searched for firebird.log in "This PC". - no such file. – Vikas Kottari Jul 09 '19 at 06:38
  • With root directory I mean the installation location of Firebird (eg C:\Program Files\Firebird\Firebird_3 or similar). In any case, without that log entry, it is hard to know what the problem is, possibly it is something like [Error occurred during login, please check server firebird.log for details (335545106)](https://www.firebirdsql.org/file/documentation/drivers_documentation/java/faq.html#error-occurred-during-login-please-check-server-firebird.log-for-details-335545106). That could indicate you are using an old version of the Firebird ado.net provider (version 4.x or older). – Mark Rotteveel Jul 09 '19 at 07:51
  • @MarkRotteveel there is no file called firebird.log at "C:\Program Files\Firebird\Firebird_3_0", also the Firebird .net provider version I am using is 6.6 – Vikas Kottari Jul 09 '19 at 08:15
  • What is your AuthServer setting (in firebird.conf)? It could also mean it is AuthServer=Legacy_Auth, while Firebird ado.net 6.6 only supports Srp when connecting to Firebird 3. – Mark Rotteveel Jul 09 '19 at 08:17
  • I wonder if he uses embedded server then, and his app has no rights to write into Program Files and writes into Virtual Storage instead... Or maybe it is some broken OnConnect trigger? – Arioch 'The Jul 09 '19 at 08:23
  • @MarkRotteveel "#AuthServer = Srp", this is the default setting. – Vikas Kottari Jul 09 '19 at 08:25
  • Are you running Firebird as a service, or did you start it manually as an application? – Mark Rotteveel Jul 09 '19 at 08:29
  • @Arioch'The That could be a possibility as well. – Mark Rotteveel Jul 09 '19 at 08:29
  • @Arioch'The I have granted the permission, that error is vanished-thank you. however, I am getting another error: "I/O error during "CreateFile (open)" operation for file "C:\FIREBIRDDB\TEST.FDB", my connection string is: "database=localhost:C:\\FirebirdDB\\test.fdb;user=sysdba;password=firebird;", I have given the write permission to test.fdb. – Vikas Kottari Jul 09 '19 at 08:52
  • I moved my database to the firebird installation folder (default) and now my code works, thanks both. – Vikas Kottari Jul 09 '19 at 09:12
  • @MarkRotteveel since his second connection script includes "localhost:" he should fall for stand-alone TCP-connected server rather than embedded, but it is always shaky in FB3 after clarity of FB2/Win – Arioch 'The Jul 09 '19 at 09:52

2 Answers2

3

If you need to run the Firebird server in application mode, run it as administrator.

This solved the problem for me. The Firebird server needs write access to some files in the installation folder.

maf-soft
  • 2,335
  • 3
  • 26
  • 49
0

I have solved this issue with the help of comments above. Steps were taken to resolve:

  1. Updated WireCrypt = Enabled in Firebird.conf file
  2. Grant read&write permissions to all application packages to the Firebird installation folder (C:\Program Files\Firebird\Firebird_3_0)
  3. I had my database at C:\FirebirdDb folder, I deleted this DB and created a new DB at the default location (i.e. the Firebird installation folder).

And here is my code:

using (var connection = new FbConnection("database=localhost:test.fdb;user=sysdba;password=masterkey;Charset=NONE;"))
{
    connection.Open();
    using (var transaction = connection.BeginTransaction())
    {
        using (var command = new FbCommand("select * from testTable", connection, transaction))
        {
            using (var reader = command.ExecuteReader())
            {
                while (reader.Read())
                {
                    var values = new object[reader.FieldCount];
                    reader.GetValues(values);
                    Console.WriteLine(string.Join("|", values));
                }
            }
        }
    }
}
Vikas Kottari
  • 495
  • 2
  • 10
  • 24
  • 1
    having world-level read-write into Program Files is bad idea security-wise. Antivirus can go crazy. Perhaps you had to analyze 1) which USER runs the FB3 process (it was LOCAL_SYSTEM by default for FB2 but maybe changed for FB3) 2) give that user the grants for the target database folder. Alternatively 3) read all the `firebird.conf` file attentively, maybe FB3 now has explicit configuration where it can or can nor create databases. In the spirit of UDF and External Tables folders whitelists, that were already in FB2's firebird.conf – Arioch 'The Jul 09 '19 at 09:51
  • This is a bad idea, do not do this. Run Firebird as a service (the default service install performed by the Firebird installer should have sufficient rights), or install it outside of Program Files. Database files do not belong in the Program Files folder. – Mark Rotteveel Jul 09 '19 at 10:55