I was able to setup external database enrolments in our Moodle courses and its working. However, the lecturers in our institution wants to view the list of students who are supposed to be enrolled in any particular course when the teacher view the students in the course. But Moodle only enrols the students into the respective course as the users/students logs into Moodle site. So I created an additional php script that runs when the teacher views the list of students in a course. This scripts checks the external database and enrols all respective students into that course before giving the list of students to the teacher. I thought some of you guys may be interested in such a functionality.
In order for this to work you need to download the attached file into the <moodle directory>/course directory and add the following line towards the beginning <moodle directory>\course\student.php file
// Auto enrol students before the students login to Moodle