• Visitors can check out the Forum FAQ by clicking this link. You have to register before you can post: click the REGISTER link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. View our Forum Privacy Policy.
  • 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

Collapse
X
  •  
  • Filter
  • Time
  • Show
Clear All
new posts

    sql server management studio

    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


    #2
    Just put the statement at the start of the script:

    use "dbname"

    Comment


      #3
      Originally posted by JoJoGabor View Post
      Just put the statement at the start of the script:

      use "dbname"
      WHS/WSS

      Comment


        #4
        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)
        Coffee's for closers

        Comment


          #5
          "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

          Comment


            #6
            Originally posted by scotspine View Post
            "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
            Coffee's for closers

            Comment


              #7
              If you know knew the amount of times I ran queries against "Master" by mistake on my home system because of the switching

              Luckily have policy at work to always use "Use DBName"

              Comment


                #8

                its not magically "switching" you just don't know how to use it!

                The behaviour is perfectly consitant, predictable and documented
                Coffee's for closers

                Comment


                  #9
                  Originally posted by Spacecadet View Post

                  its not magically "switching" you just don't know how to use it!
                  it sounds as though you've read the manual???

                  Comment


                    #10
                    Originally posted by scotspine View Post
                    it sounds as though you've read the manual???
                    Thats not always such a bad thing

                    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
                    Coffee's for closers

                    Comment

                    Working...
                    X