One issue I’ve run across frequently during development is restoring a database to a newer state. Often, when I want perform the restore, there are active connections to my development database, so restoring will fail.
Of course, StackOverflow had the answer to this, but I’ve searched for the solution to this problem enough times where it made sense for me to finally write it down.
Script to kill all connections to a database (More than RESTRICTED_USER ROLLBACK)
User AlexK posted this excellent solution:
For MS SQL Server 2012 and above
DECLARE @kill varchar(8000) = '';
SELECT @kill = @kill + 'kill ' + CONVERT(varchar(5), session_id) + ';'
WHERE database_id = db_id('MyDB')
For MS SQL Server 2000, 2005, 2008
DECLARE @kill varchar(8000); SET @kill = '';
SELECT @kill = @kill + 'kill ' + CONVERT(varchar(5), spid) + ';'
WHERE dbid = db_id('MyDB')
After installing Visual Studio 2017 a few months back, I noticed that some projects were loading strangely, while others loaded just fine. The two main issues I experienced were:
- Documents I had open on my previous run of VS wouldn’t load upon running the Visual Studio 2017 application
- Windows I had arranged in my multi-monitor layout were not loading where I expected them
A quick Stack Overflow search led me to the answer regarding the first: the .suo file had become corrupt and needed to be deleted. Once I knew that, the trick was finding the .suo file:
- From the directory containing your solution file (.sln), open the folder named “.vs”.
- In the “.vs” folder, open the folder that has a name matching your solution name.
- Inside the solution folder, there may be multiple folders, one for each version of Visual Studio
- v14 is for Visual Studio 2015
- v15 is for Visual Studio 2017
These folders will contain your .suo file, which is hidden by default in Windows, so you need to enable “Show hidden files, folders, and drives” in your Folder options in order to see it. For instructions on that (Win 7,8, or 10), see the following article: https://www.howtogeek.com/howto/windows-vista/show-hidden-files-and-folders-in-windows-vista/
After you’ve found the .suo, go ahead and delete it (make sure Visual studio is not running with the solution open). A new one will be created for you when you open the solution file the next time.
I still haven’t found a solution to my second issue (I will definitely write about it if I find one).
What the SUO (Solution User Options) file controls
After solving my problem, I decided to take a look at the responsibilities of the .suo file. Microsoft’s documentation (VS 2015 version – 2017 isn’t available at the time of this writing) isn’t very forthcoming in detailing what exactly the SUO is doing. Based on digging around on the web, it seems that the following are its responsibilities (among others):
- Remembers last open files
- Remembers breakpoints
- Remembers expanded nodes in solution explorer
- Remembers startup project
- Remembers last open tool windows and their positions
- Remembers watch window contents
The file is encoded and not human-readable, so it’s not something you can simply hack around with like you can a solution (.sln) or project (.xxproj) file. It should not be added to version control.