segunda-feira, abril 10, 2006

Connecting to Firebird in C#

As i promissed i ll start posting some basic C# using firebird, first of all lets see how to open a simple connection using the firebird driver and C#.

First you need to add a reference to FirebirdSql.Data.Firebird in your project, and add: using FirebirdSql.Data.Firebird to your code.

Now, to open a connection, just do it:

private FbConnection con = new FbConnection("User=SYSDBA;" +
"Password=masterkey;" +
"Database=/path/to/your/database.gdb;" +
"DataSource=192.168.0.1;" +
"Port=3050;" +
"Dialect=3;" +
"Charset=ISO8859_1;");
try {
con.Open();
} catch (Exception ex) {
MessageBox.Show(ex.ToString());
}

Difficult isnt it?

4 comentários:

Anônimo disse...

I have started learning C# a week ago, but I have years of Delphi experience.
Trying out your code as is results in nothing, which means it must be incomplete.
Not the end of the world I know - but for someone in my position it means I will have to search for firebird on C# elsewhere. This should be a concern for the editor?

Fábio Gomes disse...

Thanks for sharing this with me.

This post is very old and at the time I didn't have much blogging experience.

You are absolutely right, the post is incomplete.

I'll create a new tutorial and post it soon.

fiShBoN3 disse...

You may see a similar example at my blog which also talks about C#. But I did it in ASP.net which still uses C# codes. See link at Using Firebird with C#/ASP.net

Kudos to Fabio for promoting Firebird! :D

Anônimo disse...

I try to connect to firebird databases 2.5 from sharpdevelop 3.1 and i get an error:

"no message error found for cod 335544972 . invalide escape sequence"

Code :
FbConnection con = new FbConnection("User=SYSDBA;" +
"Password=masterkey;" +
"Database=d:\\firebird\\EcoManager.fdb;" +
"DataSource=192.168.1.102;" +
"Port=3050;" );