Dan Rigsby - Coding Up Style

Developer.Speaker.Blogger

Archive for the 'Tips' Category


SQL Server 2008 Error: Saving changes is not permitted

Posted by Dan Rigsby on 26th September 2008

If you have been playing with SQL Server Management Studio 2008 and are modifying tables in the designer, you may run into this error:

Saving changes is not permitted. The changes you have made require the following tables to be dropped and re-created.  You have either made changes to a table that can’t be re-created or enabled the option Prevent saving changes that require the table to be re-created.

Here is a screenshot:

SSMS1

In the 2008 , they have added a new option to prevent saving of changes that will require a table re-creation.  If you think about it, this is a good thing.  If you are running a production database, you want maximum performance.  If Management Studio needs to re-create a table to apply a change that means it needs to create a copy of the table, transfer the data, create the new table, move the data over, delete the old stuff, etc.  This can potentially be a major operation. 

However, if you don’t want this feature enabled or our just working with a development or test database, it is easy to turn off.  Just open up the Options window in Management Studio and go to “Designers –> "Table and Database Designers”, find the “Prevent saving changes that require table re-creation” option, and turn it off.

SSMS2

DotNetKicks Image

Posted in MSSQL, Tips | 5 Comments »

Remotely Log Off Remote Desktop Users

Posted by Dan Rigsby on 26th August 2008

I frequently use Remote Desktop to access various PCs here at work and nothing annoys me more than seeing this message box:

RemoteDesktopExceeed

This is caused when “The terminal server has exceeded the maximum number of allowed connections.”, right?  Basically, this happens because Windows by default only allows two simultaneous terminal services connections to the same machine.  If you see this message, then there is already that number of people logged in, and you cannot connect until one of the sessions logs off.

Usually what happens is that people don’t explicitly log out of machines when they disconnect from remote desktop which causes their “rogue” sessions to remain active.  You could just nicely ask everyone if they would please “log off” before disconnecting their sessions, but is there something else we can do?

To perform the commands I am about to show you, you need to be an administrator on the target machine.  If you aren’t you can’t perform these commands.  However, in most development and test environments, hopefully this won’t be an issue.

How to query for users on a machine

First, how can we query to find out what users have a session on a remote machine?  Windows provides the qwinsta.exe command which we can use to query for the sessions that are running  The format is as follows:

qwinsta /server:<serverName>
 

Here is an example running this command against one of my local machines.  Notice it shows the username, state, and the ID of the session.

cmd3

You can also use quser.exe:

quser /server:<serverName>
 
Here is the same example above but notice it also when they logged in and how long they were idle.

cmd1

How to log a user off of a machine

Now that we know what users are on a machine, how can we force one to disconnect? Again, there is a handy little command called logoff.exe that we can use to force a user to log off of a machine based off of their session ID.  The format is as follows:

logoff <sessionId> /server:<serverName>
 

Here is an example running this command against one of my local machines.  Notice that I used the session ID that I found from the quser.exe command above.

cmd2

Warning: If you remotely log off a user, their log session goes away which could mean that the unsaved data is lost, or if the user is in the middle of an activity, they may come down to your office to chew you out.

kick it on DotNetKicks.com

Posted in Tips, Windows | 8 Comments »