How to connect mod_dbd with various databases

Hello,
This article is briefly describing the basic steps you should follow to configure mod_dbd and make it “understand” different databases.
The article mostly goes by those who don’t want to know mod_dbd deeply but only have a desire to get Ape database modules working. More specific information you may find in “Introduction to database functionality of Helicon Ape” and “mod_dbd: Saying technically”.

Where and how to write mod_dbd configuration

The module directives are almost compatible with Apache mod_dbd but we’ve extended their scope and, as opposed to Apache, you may write mod_dbd directives in any configuration context: within <Directory>, <Location> and <VirtualHost> statements, in .htaccess and httpd.conf files.

Only two directives are required—DBDriver and DBDParams. Both are essential for creating a database connection and you will just have an error if mod_dbd can’t retrieve one of these directives values. By the way, error.log is very useful in such cases. It may give you a hint why something isn’t working.

The other mod_dbd directives may be omitted and then the default values are applied. We’ve taken them from original mod_dbd:

DBDPersist on
DBDExptime 300
DBDMax 10
DBDMin 1

Technical details of these directives are provided in “mod_dbd: Saying technically” article.

Note regarding DBDParams. mod_dbd doesn’t parse directive’s parameter but simply passes it to a database driver. It means that the directive doesn’t have any special syntax for connection strings, instead you should use database-specific connection string arguments.

Also please don’t use the following connection pooling arguments: Pooling, Connection Lifetime, Max Pool Size and Min Pool Size. They are automatically supplied by mod_dbd through its directives.

Here is a web-site which might be very helpful in connection string design: http://www.connectionstrings.com.

Microsoft SQL Server

mod_dbd natively supports SQL Server version 7.0 or higher. It’s not required to install any additional database providers, so the piece of code as follows would be enough:

DBDriver mssql
DBDParams "Data Source=server;Initial Catalog=database;  User ID=database;Password=password"

You may use the same connection string as in your web-site engine. Please refer to Microsoft SQL Server documentation for more details.

Oracle

Oracle database is natively supported. No additional software required. The following example illustrates a general way to connect to Oracle database:

DBDriver oracle
DBDParams "Data Source=server;Initial Catalog=database;  User ID=database;Password=password"

Note! mod_dbd basically uses Microsoft drivers for Oracle, however it’s possible to use Oracle drivers. Please find more information in the “Others” section below.

MySQL

There is no native support for MySQL in Helicon Ape. However it’s very easy to get mod_dbd working with this database. The best way is to install MySQL Connector for .NET. After installation please open C:\Windows\assembly folder and find MySql.Data assembly. You should open its properties dialog to get a few important values:

These values should be passed into DBDriver directive as a second argument with the following syntax:

DBDriver mysql "MySql.Data, Version=6.2.2.0,   Culture=neutral, PublicKeyToken=c5687fc88969c44d"
DBDParams "Data Source=server;Initial Catalog=database;  User ID=database;Password=password"

This is how to make mod_dbd know about MySql.Data assembly. It provides interface to MySQL database through ADO.NET technology.
Although on a shared hosting you may copy MySql.Data.dll into the same location as Helicon.Ape.dll, then your configuration would be just like this:

DBDriver mysql
DBDParams "Data Source=server;Initial Catalog=database;  User ID=database;Password=password"

In spite of the fact that the method above is much better, you have another option. It also requires additional software—MySQL ODBC connector. ODBC works much slower and we don’t recommend this approach, however if you prefer it—here is an example:

DBDriver odbc
DBDParams "Driver={MySQL ODBC 5.1 Driver};Server=server;Database=database;  User=root;Password=password;"

Please pay attention to the mandatory argument Driver. Your version may be different.

Others

We have considered only three database systems, however this isn’t a limit for mod_dbd. It’s capable of working with almost every database which supports ADO.NET, ODBC or OLEDB interface. And here is some explanation:

ADO.NET

This way requires a bit of software development knowledge! If you have ADO.NET connector for one database system, knowing a full name of a connection class it provides you may load the connector as follows:

DBDriver adonet "System.Data.SqlClient.SqlConnection, System.Data,  Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"

The code above loads Microsoft SQL Server connector.

ODBC

For this approach you need to install ODBC provider and know its name. The following example demonstrates connection to MySQL through ODBC:

DBDriver odbc
DBDParams "Driver={MySQL ODBC 5.1 Driver};Server=server;Database=database;  User=root;Password=password;"

OLEDB

Like in case with ODBC you should have OLEDB provider installed. The following example demonstrates connection to Microsoft SQL Server through OLEDB:

DBDriver oledb
DBDParams "Provider=SQLOLEDB;Data Source=server;  User ID=user;Initial Catalog=password"

Summary

We’ve described different approaches to connection mod_dbd with various database systems. Please notice that internal behavior and connection string format are very dependant on a particular database driver. However such feature as connection pooling works in any case because it’s a natural capability of mod_dbd.

Yours sincerely,
Helicon Tech team.

This entry was posted in Helicon Ape and tagged . Bookmark the permalink.

Comments are closed.