Firebird ADO.NET provider FormatException

I’ve spent almost an hour searching for a solution to a silly problem I’ve faced with using Firebird embedded database in C#. I was writing a data mapper that takes an object and saves it to the database using stored procedures. Data and procedure parameter names is taken from object’s properties, marked with a special attribute.

When I started testing, a strange exception came from FirebirdClient ADO.NET provider when trying to execute the procedure. It was a FormatException with message “Input string was not in a correct format”, which was completely unrelated to anything I’ve written. What caused the problem is:

The order in which you add parameters to FbCommand object must match the order of stored procedure parameters order.

So, if you have a class like this:

public class Foo
    // this attribute tells that property should be passed to stored procedure with name "bar1"
    public int Bar1

    public string Bar2

you must declare your stored procedure parameters in the order in witch you define your properties:

  "bar1" INTEGER,
  "bar2" VARCHAR(100)

Quite a silly issue in my opinion 🙂


One thought on “Firebird ADO.NET provider FormatException

  1. Thanks a lot. I was busy already several hours and indeed, unrelated to anything I was doing. Fixing the order solved the problem. This really silly. Thanks for the article !!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s