Skip Navigation Links
Home
About
Blog
Resume
Calendar Demo
Map Demo
Birthday Odds
Mozy

I'm using Microsoft Visual Web Developer Express Beta 2 to try to do the same thing I've done with my Firebird Embedded C# DDL console application.

I started out using the same versions of Firebird related libraries:

fbembed.dll version 1.5.2.4731, and FirebirdSql.Data.Firebird.dll version 1.6.3.0.

I kept getting a cannot find fbembed.dll error, no matter where I stuck the fbembed.dll in the web site (I probably could have put it in the path, but I don't think I would have that option at a hosting provider).

I upgraded to the latest FirebirdSql.Data.Firebird library (version 1.7.1.0 - which is referred to as 1.7.1-RC1).

I was able to download NANT and get it to build myself (I figured I'd have to hardcode the path to fbembed.dll in the code).  Hardcoding the path worked, but I did not really like that as a solution.

I found someone who tested using something like:

[DllImport("kernel32")]
public static extern int LoadLibraryA(string lpLibFileName);

[DllImport("kernel32")]
public static extern int FreeLibrary(int hLibModule);

int lnHandle = LoadLibraryA(Server.MapPath("~/bin") + "fbembed.dll");

Code here to interact with the database

FreeLibrary(lnHandle);

To load up the fbembed.dll and then the application would continue to use the one loaded instead of having to look for it and not find it.  That worked with the version 1.7.1.0 library, but I could not get it to work with the version 1.6.3.0 library.

I then tried removing the LoadLibraryA stuff, and the 1.7.1.0 library still worked when the fbembed.dll was in the \bin directory. I tried sticking it in the \App_Data directory just for fun and I got the cannot find fbembed.dll error again.

Here is the code beside file contents from the web page that does the work.

using System;
using System.Data;
using System.Configuration;
using System.IO;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using BALConsultingNet.Data;

public partial class _Default : System.Web.UI.Page
{
   protected void Button1_Click(object sender, EventArgs e)
   {
      //Define the name of the database
      string lsDBName = "Test";

      //Define the directory where the database file will go
      string lsDataDir = Server.MapPath("~/App_Data");

      //Create the database, returning the file name created
      string lsDataFile = DDL.CreateDatabase(lsDBName, lsDataDir);

      //Define a table for the database using the DataTable object
      DataTable loTable = new DataTable();
      loTable.TableName = "Person";

      //Define a column in the table (name it "id" and have it be an Integer)
      DataColumn loColumn = new DataColumn("id", Type.GetType("System.Int32"));

      //Don't allow Nulls in this column
      loColumn.AllowDBNull = false;

      //Make this an AutoIncrement column
      loColumn.AutoIncrement = true;

      //Add it to the table definition
      loTable.Columns.Add(loColumn);

      //Add a constraint to make this column the primary key
      UniqueConstraint loPrimaryKey = new UniqueConstraint("PK", loColumn);

      //Add the constraint
      loTable.Constraints.Add(loPrimaryKey);

      //Add some text columns
      loTable.Columns.Add("namefirst", Type.GetType("System.String"));
      loTable.Columns.Add("namemiddle", Type.GetType("System.String"));
      loTable.Columns.Add("namelast", Type.GetType("System.String"));

      //Create the table
      // associated generator for the AutoIncrement field
      // associated constraint for the Primary key
      DDL.CreateTable(lsDataFile, loTable);

      //Create a stored procedure to use to insert data into the table (and return
      // the "id" of the record created
      string lsStoredProcedureInsertName = "SP_" + loTable.TableName + "INSERT";
      DDL.CreateStoredProcedureInsert(lsDataFile, loTable, lsStoredProcedureInsertName);

   }
}

I had to make a slight change to the CreateDatabase method of my DDL library to use a connection string instead of a HashTable.

BALConsultingNet.Data.cs.2.txt (11.99 KB)

Here is how the web solution is set up.

Categories: Development | Database
Posted by Brian Lakstins on Tuesday, September 27, 2005 4:00 PM
Permalink | Comments (0) | Post RSSRSS comment feed
Comments are closed