| DotNetFirebird Using Firebird SQL in .NET. |
|
Home
Features
Download
Documentation
FAQ
Tools and Code
About
Blog
|
Friday, May 27, 2005
Problems with Creating a New Database using Embedded Firebird
Vitani is asking: "I'm having the same problem as Victor Tai. The creation and first connection is fine, but if I close my app and restart it, the Connection.Open fails." This is the sample code he sent:
private void button1_Click(object sender, System.EventArgs e)
{
FbConnection cnn = new FbConnection("ServerType=1;User=SYSDBA;Pooling=false;" +
"Password=masterkey;Dialect=3;Database=" + this.txtFilename.Text);
if (!System.IO.File.Exists(this.txtFilename.Text))
{
Hashtable parameters = new Hashtable();
parameters.Add("User", "SYSDBA");
parameters.Add("Password", "masterkey");
parameters.Add("Database", this.txtFilename.Text);
parameters.Add("ServerType", 1);
FbConnection.CreateDatabase(parameters);
}
cnn.Open();
FbDataAdapter da = new FbDataAdapter("SELECT * FROM RDB$RELATIONS", cnn);
DataTable dt = new DataTable("RELATIONS");
da.Fill(dt);
da.Dispose();
this.dataGrid1.DataSource = dt;
}
For the first time it runs fine but when you run it the second time (when the database is already created) it throws an exception:
FirebirdSql.Data.Firebird.FbException: internal gds software consistency check (Internal error code (165))That means the database is corrupted and can't be open. So where is the problem? Here: cnn.Open();You don't have to supply an open connection to the FbDataAdapter. If you supply an unopened connection, FbDataAdapter opens it when needed and closes it at the end. But when you supply an open connection it doesn't close it. The code should be changed this way: private void button1_Click(object sender, System.EventArgs e)
{
FbConnection cnn = new FbConnection("ServerType=1;User=SYSDBA;Pooling=false;" +
"Password=masterkey;Dialect=3;Database=" + this.txtFilename.Text);
if (!System.IO.File.Exists(this.txtFilename.Text))
{
Hashtable parameters = new Hashtable();
parameters.Add("User", "SYSDBA");
parameters.Add("Password", "masterkey");
parameters.Add("Database", this.txtFilename.Text);
parameters.Add("ServerType", 1);
FbConnection.CreateDatabase(parameters);
}
FbDataAdapter da = new FbDataAdapter("SELECT * FROM RDB$RELATIONS", cnn);
DataTable dt = new DataTable("RELATIONS");
da.Fill(dt);
da.Dispose();
this.dataGrid1.DataSource = dt;
}
When working with FbCommand I recommend using the "using" block like this:
FbCommand cmd = new FbCommand("INSERT INTO table (par1) VALUES (@par1)");
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@par1", "parameter 1");
using (cmd.Connection = new FbConnection(this.connectionString))
{
cmd.Connection.Open();
cmd.ExecuteNonQuery();
}
This way you don't have to surround the code with try {} and close the connection in the "finally" section.
Thursday, May 26, 2005
Firebird 2.0 Alpha 2: Index Size Limit Removed
It's nice to see that the index size limit I wrote about the last time was removed in Firebird 2.0 Alpha 2. See the Firebird 2.0 Alpha 2 Release Notes (PDF; use right click and "Save as..." because ibphoenix.com doesn't serve PDF correctly).
Thursday, May 19, 2005
Firebird Index Size CalculatorFirebird has an annoying limitation of index size. The maximum index size is 252 bytes. If you are using a single-field index there is no problem with the calculation. However, for multi-field indices it is more complicated and the index consumes more space than just the size of the fields added together. If you need to check your fields before creating an index, this online Index size calculator created by Ivan Prenosil can help. Securing Firebird with SSLRecently I have found a good guide on securing the connections to Firebird with SSL (using stunnel). Read it on IBPhoenix: Secure connections to Firebird with Stunnel. Firebird doesn't support any channel encryption (not even a password encryption). This doesn't have to be a problem when you are running the database on the same server as the client (e.g. when the only client is the web server and access from the network is restricted). If you have the database on a different computer than the client it is recommended to wrap the connection using SSL. Don't forget to bing the Firebird server to the loopback IP address (127.0.0.1) otherwise the SSL connections will be just optional. There are two possible scenarios when using stunnel:
Tuesday, May 03, 2005
GotDotNet: Enterprise Library for Firebird
See the workspace: http://www.gotdotnet.com/Workspaces/Workspace.aspx?id=1f216647-4011-40cd-8dc7-174eda97aad1.
Previous
Archives
Copyright © 2005 - 2007 DotNetFirebird |