1
votes

I'm trying to connect to a embedded firebird database using de following code:

    var cmm = new FbCommand();
    var csb = new FbConnectionStringBuilder();
    csb.ServerType = FbServerType.Embedded;
    csb.UserID = "SYSDBA";
    csb.Password = "masterkey";
    csb.Dialect = 3;
    csb.Charset = "UTF8";
    csb.Database = @"TESTE.FDB";
    cmm.Connection = new FbConnection(csb.ConnectionString);
    try
    {
      cmm.Connection.Open();
      cmm.CommandText = "SELECT NOME FROM TESTE WHERE ID=2";
      MessageBox.Show(Convert.ToString(cmm.ExecuteScalar()));
    }
    catch (Exception ex)
    {
      MessageBox.Show(ex.Message);
    }
    finally
    {
      cmm.Connection.Close();
    }

The query execute depending of the directory of the program. If I open the program in the directory "C:\np" or other local directory, it works normally. But, if the directory is a network mapping, I receive the following error: "Unable to complete network request to host "psf". Failed to establish a connection."

What can I do to resolve this situation? Thanks.

1
Firebird by default doesn't allow opening databases from a network share. Will post a detailed answer later. - Mark Rotteveel

1 Answers

2
votes

Firebird doesn't allow opening databases on network shares by default, as this could lead to database corruption as Firebird needs either exclusive access to a database, or instances sharing a database file need to coordinate access using a lock file local to the server. Access through a network share means that multiple instances from multiple hosts could access the same database file, and that is not how Firebird is designed to be used.

If you want to access a single Firebird database from multiple hosts then you should setup a Firebird server and configure all clients to connect to that server, you should not use a network share.

However if you really want to access a database on a network share, then you can set the option RemoteFileOpenAbility in firebird.conf to 1. Given the risk of file corruption and data loss I strongly advise not to use this option, but use a Firebird server instead. Make sure you read the warning in the config file as well.