Thanks, Inaki.
Yes, the default role is set to 'student'.
Since posting my question I noticed that the mdl_role_assignments table does indeed show 'database' for the enrol column. I see this, together with the students who are enrolled, by executing
SELECT r.shortname, u.username,c.shortname,ra.enrol FROM mdl_user u JOIN mdl_role_assignments ra ON ra.userid = u.id JOIN mdl_role r ON ra.roleid = r.id JOIN mdl_context con ON ra.contextid = con.id JOIN mdl_course c ON c.id = con.instanceid AND con.contextlevel = 50 WHERE r.shortname = 'student';
Nonetheless, students log in and get the "Course is not enrollable" message. The documentation says that "enrollable" pertains to interactive enrolment only, not external database enrolment, so I imagine that users see this because Moodle is unhappy with the database enrolment. I tried playing with startdate, visible, enrollable, and so on, but to no avail.
One thing I should mention is that the configuration of the external DB plugin is being done by a php script that sets the right values into the mdl_config table. At least I *think* they are the right values! When I manually go to the External
Database enrolment plugins screen everything certainly seems to be in order. The value for the mdl_config column named 'enrol_plugins_enabled' is 'manual,database'. (I even tried setting it to 'database, manual' to see if order mattered. You can see how desperate I have become!)
There must be something that makes Moodle refuse to recognize the enrolments. It must be some setting having to do with each course, and since they were all created dynamically from a "template course" I created for this purpose it would not surprise me that I screwed up there. The template course does not have any enrolments associated with it-- could that be relevant? The settings for the template seem innocuous to me: it is not enrollable, it is visible, its start date is in the past, and so on. Does any of this make sense to you?
All help is most appreciated because I am quite stuck and also running out of time...
Alan