SQL Sam and the Phantom Connection - Solution!

"What do you mean, Sam?" Jimmy asked. "I don't see any connections..."

"Don't forget, Jimmy, that when you run a scheduled task, the SQL Executive Service makes a connection into SQL Server. And it has to establish a connection to a particular database."

"How does it decide what database to connect to?" asked Jimmy.

"Keep looking," smiled Sam. "You'll see it..."

"Oh!" Jimmy exclaimed. "It's right there, in the task options: Database testDb! I put TestDb as the database name because I figured that was the database where the work should be done."

"Well, that does make sense," admitted Sam. "But in this case, it keeps you from loading the database properly. You'll want to have the connection log into a different database."

 

Jimmy changed the database the scheduled task used to master, like this:

This time, when Jimmy ran the task, it worked. Jimmy was well on his way to creating a weekly scheduled process to check his databases by using an offline server. SQL Sam cautioned Jimmy that sometimes there are true phantom connections. These seem to be left behind from disconnected applications, and they won't show up in sp_who. They do have an annoying tendency to keep the sa from doing operations that require exclusive database access (like a database load). So far, the only solution to that problem seems to be to stop and restart SQL Server.

Go read more exciting SQL Sam Cases!

See the story behind the story in Behind the SQL: The Making of SQL Sam!


Steve Hontz is President of The Bit Corner, Inc., a Phoenix-based consulting firm specializing in Windows NT, C++, and SQL Server development. You can reach him at steve@bitcorner.com.