Programmatically creating the Oracle Lite database

Let's take a look at the CreateSalesForceDatabase method equivalent for Oracle Lite. It does what it says, which is to create a database named SalesForce in Oracle Lite and to generate all the sales force application tables automatically. The differences now are that:

• You will be using the oracleEngine class to generate the new database

• You will be using the oracleConnection class to connect to the database

In the CreateSalesForceDatabase implementation you will first need to declare a few function-scope variables:

OracleConnection _connection; OracleCommand _command; ResourceManager _ResourceManager;

The CreateDatabase method in OracleEngine is a shared function, so you can call the method directly to create the salesforce DSN and database, and set the database password to admini2 3:

OracleEngine.CreateDatabase("salesforce", "salesforce", "admin123");

catch (Exception ex) {

MessageBox.Show(ex.Message, "Create database",

MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Buttonl); return false;

Now that the database has been created, you will attempt to connect to it and execute the SQL statements stored in the TableSchema.resx resource file to build the entire schema required for the sales force application. You can start by first opening a connection to your newly created database:

_connectionString =


_connection = new OracleConnection(_connectionString);


catch (Exception ex) {

MessageBox.Show(ex.Message, "Connecting to database", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Buttonl);

Now latch .NET's ResourceManager class on to the TableSchema.resx resource file like this:

_ResourceManager = new ResourceManager("CRMLive.TableSchema", Assembly.GetExecutingAssembly());

Lastly, create the oracleCommand object to run all the SQL statements retrieved from the resource file. This will create the tables together with their corresponding sequences needed for the application to run:

_command = _connection.CreateCommand();

_command.CommandText = _ResourceManager.GetString("AccountTasks_ SQL");


_command.CommandText = _ResourceManager.GetString("AccountTasksSeq _SQL");


And, of course, don't forget to close and dispose of the database connection at the end!

_connection.Close(); _connection.Dispose(); _connection = null; return true;

Was this article helpful?

0 0

Post a comment