Publish date: 2010-08-25

How to create a Firebird or InterBase database by using ADOX and Visual C# .NET (or VBScript)

To run all examples in this article you need IBProvider. If you didn’t install provider yet, download them right now!

For setup new database parameters you can use new IBProvider initialization properties:

Create Firebird/InterBase database using VBScript:

dim catalog

set catalog=createobject("ADOX.Catalog")

wscript.echo "Database creation"

call catalog.create("Provider=LCPI.IBProvider.3;" & _
                    "location=localhost:d:\database\test_ibp.fdb;" & _
                    "user id=SYSDBA;" & _
                    "password=masterkey;" & _
                    "ctype=win1251;" & _
                    "IBP_NEWDB: Database Page Size=8192;" & _
                    "IBP_NEWDB: Database Dialect=3;" & _
                    "IBP_NEWDB: Default Charset=UNICODE_FSS")

wscript.echo ""
wscript.echo "Server Type     :"&catalog.ActiveConnection.Properties.Item("DBMS Name").Value
wscript.echo "Server Version  :"&catalog.ActiveConnection.Properties.Item("DBMS Version").Value
wscript.echo "DB Page Size    :"&catalog.ActiveConnection.Properties.Item("IB Database Page Size").Value
wscript.echo "Database Dialect:"&catalog.ActiveConnection.Properties.Item("IB Database Dialect").Value

call catalog.ActiveConnection.BeginTrans()

dim rs
set rs=catalog.ActiveConnection.Execute("select RDB$CHARACTER_SET_NAME from RDB$DATABASE")

wscript.echo "Database Charset:"&cstr(rs(0).value)

call catalog.ActiveConnection.CommitTrans()

Create Firebird/InterBase database using Visual C#:

See code example on Visual C#:

  1. At first you need to add reference to the COM-library «Microsoft ADO Ext 2.X for DLL and Security»
  2. Run the following code:
[TestFixture]
public class SamplesCreateDatabaseViaADOX
{
    string str_path_db = "d:\\test_ibp.fdb";

    [Test(Description = "Create Database Via ADOX library sample")]
    public void CreateDatabaseViaADOXTest()
    {
        string str_provider = "LCPI.IBProvider.3";
        string str_userid = "SYSDBA";
        string str_password = "masterkey";
        string str_ctype = "win1251";

        string str_new_db_default_charset = "UNICODE_FSS";
        string str_new_db_dialect = "3";
        string str_new_db_page_size = "8192";

        // create database
        ADOX.Catalog cat = new ADOX.Catalog();
        cat.Create(string.Format(
                    "Provider={0};" +
                     "Location=locahost:{1};" +
                     "User id={2};" +
                     "password={3};" +
                     "ctype={4};" +
                     "IBP_NEWDB: Database Page Size={5};" +
                     "IBP_NEWDB: Database Dialect={6};" +
                     "IBP_NEWDB: Default Charset={7}",
                     str_provider, str_path_db, str_userid,str_password, str_ctype,
                     str_new_db_default_charset,str_new_db_dialect, str_new_db_page_size));

         OleDbConnection cn = new OleDbConnection(string.Format(
                     "Provider={0};" +
                     "Location=localhost:{1};" +
                     "User id={2};" +
                     "password={3};" +
                     "ctype={4};",
                     str_provider, str_path_db, str_userid, str_password, str_ctype));

         // test connection
         cn.Open();
         cn.Close();
    }

    [TearDown]
    void CleanUp()
    {
        // cleanup - delete database if exists
        if (System.IO.File.Exists(str_path_db))
            System.IO.File.Delete(str_path_db);
    }

One more example of database creation using CREATE DATABASE DDL command

See example: CREATE DATABASE using DDL command.


Tags: ADOX, Visual C#, Create Database, Firebird, InterBase, VBScript.
Author: Andrew A. Merkulov  

Publish date: 2010-08-25. Copyright: IBProvider. This material may be reproduced on other web sites, without written permission but link https://www.ibprovider.com/eng required.