in edit: babylon...just for reference you can go long/short same ticker in ameritrade, but last entered position must be cleared first. i know as i found out the hard way with that; their phrase was "can't break box"
Usually not. Some brokers will just stop the trade. Others will use the buy to cover all or part of the short, or use the short to sell off all or part of the long.
Technically, those brokers that will allow you to do it are supposed to get a letter from you specifying that you want a "boxed" postion.
I get around the restriction by either using different brokerages, or by using brokerages that maintain separate long and short sub-accounts within each account.