I read that Windows server is constricted to 20 characters maximum user name length. What is the maximum domain name length?
This way I can store the values in a database with the correct length:
DOMAIN\USERNAME = 21 characters + domainNameMaxLength = ?
It sounds like you're mixing name limitations up a little bit. Computer name limitations, domain name limitations, and SamAccount name limitations are different things altogether.
The SamAccount name limitation is 20 characters.
The NetBIOS name limitation (single label computer name) is 15 characters.
For info on DNS and FQDN name limitations, see here:
http://support.microsoft.com/kb/909264
Disabling NetBIOS has nothing to do with the NetBIOS computer name. Every computer object has a NetBIOS computer name regardless of whether or not NetBIOS is enabled.
The NetBIOS name of a domain is also limited to 15 characters.
So that would be: DOMAIN\USERNAME = 15 + 1 + 20 characters = 36 characters.