You need to test network connectivity with your app, suggestions?
Mar
3
Written by:
Monday, March 03, 2014 9:43 PM
You’re writing an app and want to test what happens when you lose your connection to the DB? I think I can help you out!
Today I was trying to finish off a small utility to list PKs from a DB. There are about 5 million and it takes about a second to process each one. The thing is, I tried to “let it go” over the weekend. This morning I got in, expecting, HOPING to see over 200,000 records processed. DOH! To my surprise, it stopped Fri around 8pm. DOH! Wha-hawppen!? Some how I lost my connection to the db. Oh snap!
Ok, so today, I wrapped my code with a while statement, some exception checks and some code for retries. Ok, great. But! Short of pulling out the cable (which is what my partner suggested with a smirk on his face, THANKS D’ARCY! LOL), I found a cool way, TWO actually. Go into Control panel, networks….a few mouse clicks later and you’re here.
(Win7)
(Win8)
(I changed the View options a bit, just in case your mileage varies on the UI).
See on the above screen cap, the Disable option? Beautiful! To disable, well……select the Disable option. To enable it again, you enable it.
Ok, so this is cool, BUT it’s kind of tedious to have to click, click, click……there’s got to be a better way?! Yup, there is!!!! It can be scripted!
I created three bat files, and with DOS and the up-Arrows, you can quickly filter through enabling and disabling your network connecting as you wish!
NicOff.bat
netsh interface set interface "Local Area Connection" Disabled
NicOn.bat
netsh interface set interface "Local Area Connection" Enabled
NicShow.bat
netsh interface show interface "Local Area Connection"
I noticed my network adapters were called something differing on my Win8 box which means my exact same batch files won’t work at home. But it’s simple enough to change.
Now that we know how to turn on and off your network connectivity at will, it’s time to grab a coffee and get coding!
Resources
StackExchange: bat file to disable ethernet adapter and then reenable it after windows log inbat file to disable ethernet adapter and then reenable it after windows log in