Which version of the DLL that your program is using depends on which build of the library your program actually linked to.
You may either need to check your linker settings and make sure that in Release you are not linking with the debug lib or check your code for any
#pragma comment(lib, "...")
and make sure you use the correct one.
Personally I have this:
#ifdef _DEBUG
#pragma comment(lib, "d3dx9d.lib")
#else
#pragma comment(lib, "d3dx9.lib")
#endif
So that the relevant version is linked with for the build. I'd put it in the actual settings but I keep the stuff on SVN and this works out as a little easier for me.