I've been though this and on my experience there are two ways
Using mutex:
http://dynamiccrmcustomization.blogspot.co.nz/2013/02/auto-number-solution-for-dynamics-crm.html
I'm sure that works well on a CRM set without load balancing (only one front end for one sql server)
I have my doubts when you are on a load balance server. I've seen people using mutex on load balanced CRM and getting duplicates. there is a long way from reading the current number, assign to the record and than auto increment. the best way is to do it
on a database transaction.
Now are you on crm 4.0 or 2011
for 2011 you can take advantage of the transactions. just create an entity to store the auto number and than you can increment it and read from it using a plugin. But you must do the operation within the transaction stage
this is a good example:
http://weblogs.asp.net/gayanperera/archive/2008/10/23/crm-4-incremental-numbering-for-any-entity.aspx
note the part saying "Next we wrote a plugin that hooked into the Pre-Create event synchronously,
check the target"
this is because the pre event is within the transaction
Pre-Event
Pre-operation
20
Stage in the pipeline for plug-ins that are to execute before the main system operation. Plug-ins registered in this stage are executed within the database transaction.
If you are on 4.0, you won't have that luxury. You can create a separated database and use a stored procedure (don't create a stored procedure on the CRM database)
I Hope I could help. If I have answered please mark as 'Answer'. If was just helpful, please vote. Thanks and happy coding! Bruno Lucas, http://dynamicday.wordpress.com/