This partly depends on what you consider a “code injection attack”.
Take an SQL injection attack, for example. The SQL query itself should never be in the executable part of the memory, because it is converted to its own code (or interpreted, or any terminology that you want to use) using the database engine. However, this SQL can still be seen as "code."
If you include only the attacker, inserting your own code that must be executed directly by the processor (for example, through a buffer overflow), and if the process does not allow you to copy data to the "code area", then it provides protection against such attacks, yes. (I don’t want to demand 100% protection, even if I can’t think of any attacking vectors, this sounds perfect, but security is a trick.)
Jon skeet
source share