Generates database access code