• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Help: NET USE always fails 1st time; 2nd try always works

kevinthenerd

Platinum Member
I have a Windows batch file that I wrote to automate interconnectivity between two database systems. (It massages the data along the way and uses various tools to get the job done.) Near the beginning of the script, I call a NET USE command to establish a connection to a network share where temporary data files will be stored during the operation.

I'm still debugging the code, but eventually I'd like to put it in a scheduled task and only worry about it when it breaks. Right now, I'm starting the code manually, and on a "cold" morning start, I get an error 53 from the NET USE. (My code has a lot of error trapping.) If I close the program and try it again seconds later, it works.

This pattern of working on a consecutive try is very repeatable. I'm tempted to write in a second attempt and move on, but I'm not comfortable with ugly code that I don't understand. I'll also have to support this code in the foreseeable future.
 
Can you write the batch file such that it keeps retrying the net use command until it is able to connect. (I use
Code:
IF EXIST P:\SomeEmptyTextFile.txt
to verify that my P: drive is mapped.)
 
Can you write the batch file such that it keeps retrying the net use command until it is able to connect. (I use
Code:
IF EXIST P:\SomeEmptyTextFile.txt
to verify that my P: drive is mapped.)

That's a better work-around than what I had in mind, and I might consider limiting it to a certain number of attempts before dying completely.

I'd still like to know the root cause, though.
 
I have a batch file that runs at startup and sometimes its net use command fails because the batch file was running before all the network services were even loaded. My solution was to simply insert a delay:

ping 123.45.67.89 -n 1 -w 5000 > nul

gives a 5 second delay. You might want to insert a delay before calling your net use, or simply call it twice with a delay inbetween.
 
Back
Top