Login or Sign Up to become a member!
LessThanDot Sit Logo

LessThanDot

Data Management

Less Than Dot is a community of passionate IT professionals and enthusiasts dedicated to sharing technical knowledge, experience, and assistance. Inside you will find reference materials, interesting technical discussions, and expert tips and commentary. Once you register for an account you will have immediate access to the forums and all past articles and commentaries.

LTD Social Sitings

Lessthandot twitter Lessthandot Linkedin Lessthandot friendfeed Lessthandot facebook Lessthandot rss

Note: Watch for social icons on posts by your favorite authors to follow their postings on these and other social sites.

Your profile

    Search

    XML Feeds

    Google Ads

    « January #Meme15 Assignment – Twitter, the Blog, taking over the universeFriday SQL Nugget #1 »
    comments

    I was restoring a TB+ sized database on our staging database today. Someone needed to use a different database but he couldn't login because the database I was restoring was the default database for the login he was using. I told him to click on the Options button in the connection dialog and specify another database. I guess there was an misunderstanding because he couldn't get it to work. This means it is time for a blog post.

    First, let's create two databases

    1. CREATE DATABASE Test1
    2. GO
    3.  
    4. CREATE DATABASE Test2
    5. GO

    Now create a new login named TestLogin with a password of Test

    1. USE [master]
    2. GO
    3. CREATE LOGIN [TestLogin] WITH PASSWORD=N'Test', DEFAULT_DATABASE=[Test1]

    Add the login we just created to the Test1 database and make the login part of the db_owner role

    1. USE [Test1]
    2. GO
    3. CREATE USER [TestLogin] FOR LOGIN [TestLogin]
    4. GO
    5. USE [Test1]
    6. GO
    7. ALTER ROLE [db_owner] ADD MEMBER [TestLogin]
    8. GO

    Add the login we just created to the Test2 database and make the login part of the db_owner role

    1. USE [Test2]
    2. GO
    3. CREATE USER [TestLogin] FOR LOGIN [TestLogin]
    4. GO
    5. USE [Test2]
    6. GO
    7. ALTER ROLE [db_owner] ADD MEMBER [TestLogin]
    8. GO

    Make sure that you can login with the TestLogin account

    Now that you know that you can login with the TestLogin account, use another account and put the Test1 in offline mode

    1. ALTER DATABASE Test1 SET OFFLINE

    Now if you try to login with the TestLogin account, you will see the following error

    Login failed for user 'TestLogin'. (Microsoft SQL Server, Error: 18456)

    Here is what you need to do, on the connect to server window, click on the options button

    That will open the Connection Properties tab

    Whatever you do, do not select Browse server... from the connect to database option, if you do that you will get the following error

    Just type the database name of the database that is not offline instead

    As you will see you can connect without a problem now

    Hopefully this will help someone else in the future also

    About the Author

    User bio imageDenis has been working with SQL Server since version 6.5. Although he worked as an ASP/JSP/ColdFusion developer before the dot com bust, he has been working exclusively as a database developer/architect since 2002. In addition to English, Denis is also fluent in Croatian and Dutch, but he can curse in many other languages and dialects (just ask the SQL optimizer) He lives in Princeton, NJ with his wife and three kids.
    Social SitingsTwitterFacebookLinkedInHomePageFlickrLTD RSS Feed
    1665 views
    Instapaper

    1 comment

    Comment from: Thomas LeBlanc [Visitor] · http://TheSmilingDBA.BlogSpot.com
    Thomas LeBlanc Excellent, never used the option button until today.

    Thanks,
    Thomas
    01/24/12 @ 07:31

    Leave a comment


    Your email address will not be revealed on this site.

    Your URL will be displayed.
    (Line breaks become <br />)
    (Name, email & website)
    (Allow users to contact you through a message form (your email will not be revealed.)