• Want to receive the latest contracting news and advice straight to your inbox? Sign up to the ContractorUK newsletter here. Every sign up will also be entered into a draw to WIN £100 Amazon vouchers!

sql server management studio

scotspine

Contractor Among Contractors
Joined
Jul 6, 2005
Messages
1,053
Likes received
3
Thanks received
3
this thing has a mind of it's own. it keeps switching the active database so that unless you're *really* careful, you can end up running a script against a database other than the one you think you are!!!!! grrrrrr

:tantrum:
 
Just put the statement at the start of the script:

use "dbname"
 
when you click on new query (or hit control-N) it will open a session to which ever database you are currently connected to. This is not constrained to the query windows.

So if you were browsing the live system in the object explorer tree and the window focus was on there then SSMS will open a DB connection to the Live database.

Once you understand the behaviour you'll realise its not just switching... its doing what it is supposed to do and it does it very consitantly.

As JoJoGabor pointed out though - adding the use <dbname> will make sure your scripts are always diverted to the correct database (unless your running a partial section of the query by highlighting then executing)
 
"it will open a session to which ever database you are currently connected to"

hmmmm..in theory, yes. i still think my copy of ssm studio has an attitude problem though.

"use "dbname""

i know, i know. i ought to do this but sometimes....you just want to be productive and get on with things...something about haste and speed comes to mind :emb
 
"it will open a session to which ever database you are currently connected to"

hmmmm..in theory, yes. i still think my copy of ssm studio has an attitude problem though.

try clicking on a db in the object explorer then click on new query
see which db you are connected to

then with the query window active click new query
see which db you are connected to

select a different db in the object explorer and click new query (whilst the object explorer window is still maintaining the application focus)
again see which db you are connected to
 
If you know knew the amount of times I ran queries against "Master" by mistake on my home system because of the switching :spank:

Luckily have policy at work to always use "Use DBName"
 
:tantrum::tantrum::tantrum:
its not magically "switching" you just don't know how to use it!

The behaviour is perfectly consitant, predictable and documented
 
it sounds as though you've read the manual??? :nerd

Thats not always such a bad thing :glasses

Seriously though, Query Analyser in Sql Server 2000 behaved exactly the same way and this behaviour was carried through to 2005 and 2008
Don't know about version 7 - I only ever did some basic admin work on that
 

Advertisers

Back
Top