0

We get .ydb files of firebird database from client. Currenlty we created a DSN with some additional installation/drivers and then access the tables and data inside the files.

We are planning to move this process to azure cloud service (not azure VM) so to avoid creating DSN etc. we need to access the .ydb files from c# code.

I could not open directly using firebird ado.net provider, throwing exceptions.

The below are the steps used to create DSN in the machine. It is working for long time.

  1. Firebird ODBC setup in Windows Server

    DSNName-DSNName1,

    Driver-IscDbc,

    Database-E:\Somefolder\FileName.ydb

    Client-C:\ProgramFiles\Firebird\Firebird2_5\WOW64\fbclient.dll

    Database Account- SYSDBA

    Password - masterkey

    Role - SYSDBA

    CharSet - None

  2. Then used the below C# code to access the FileName.ydb using the DSN.

    using (var connection = new OdbcConnection("DSN=DSNName1"))
    {
        connection.Open();
        var schema = connection.GetSchema("Tables");
        var tableNames = new List<string>();                    
    }
    

Now to modify the above DSN creation process, I added FirebirdSql.Data.FirebirdClient nuget package in the c# solution.

string connectionString = "User=SYSDBA;" + "Password=masterkey;" +
"Database=E:\\Somefolder\\Filename.ydb;" + "Dialect=3;" + "Charset=NONE;" +
"Role=SYSDBA;";

FbConnection fbConn = new FbConnection(connectionString);
            fbConn.Open();

            var schema = fbConn.GetSchema("Tables");

It throws exception on fbConn.Open(); - Unable to complete network request to host "localhost".

How to open the .ydb files in C# directly without creating a DSN?

3
  • Show us what you have so far, post your code to the question. And also what error are you getting? Commented Jul 12, 2016 at 9:31
  • Do you actually have a Firebird server installed? Because the driver is trying to connect to a Firebird server on localhost. If you don't want to install Firebird, you will need to use the Firebird ADO.NET provider and an embedded Firebird install. Commented Jul 12, 2016 at 10:58
  • 1
    Also note that ydb is not a typical suffix for Firebird databases (usually it is fdb, or maybe gdb). Commented Jul 12, 2016 at 11:00

1 Answer 1

2

The biggest problem you seem to have is that you do not have Firebird server installed or running, so you can't actually connect to it and ask it to open the database file.

You can download Firebird from http://www.firebirdsql.org/en/downloads/ (you will probably need Firebird 2.5) and install it. Then in a project that references FirebirdSql.Data.FirebirdClient you should be able to connect with as little as:

using (var connection = new FbConnection(@"User=username;Password=password;Database=D:\data\DB\database.fdb"))
{
    connection.Open();
}

If for some reason you don't want to install Firebird server, you will need to use Firebird embedded (which can also be downloaded from the link above).

You will need to make sure that your application is either running 32 bit or 64 bit, and download the right Firebird embedded package. Put it in the path, or in the folder of your executable. In the URL you need to add ServerType=1 to get Embedded support (the default is ServerType=0):

using (var connection = new FbConnection(@"ServerType=1;User=username;Password=password;Database=D:\data\DB\database.fdb"))
{
    connection.Open();
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.