What version of NI-VISA are you using? You may want to upgrade to the latest version by going to this page. Make sure you have a compatible operating system prior to installing. You mentioned that you are using LabVIEW and Measurement and Automation Explorer (MAX). Are you sending commands successfully in MAX or in LabVIEW? MAX will automatically open and close sessions for you, so you may want to check that this is done in your code on each run. Also, make sure that you have proper timing (for example, make sure there is enough time programmed into your code for the instrument to respond properly). I see several errors in the code you say is working. Are any of these error causing problems?
Please answer these questions and try these suggestions and let me know an updates. Have a great day!