Tag: SQLNewBlogger

  • Start SQL Server in Single User Mode

    Another post for me that is simple and hopefully serves as an example for people trying to get blogging as #SQLNewBloggers.

    I saw someone recently ask how to reset the sa password, and myself (along with a few others) suggested starting SQL Server in single user mode as an administrator. The poster had problems and at one point I suggested using the command line, which I had used in the past. However that didn’t’ work,  and when I tried it myself, it gave me errors.

    The errors were Operating System errors, which indicated that the errorlog location wasn’t accessible by me. So I decided to elevate my privileges.

    2015-07-06 13_48_41-Start menu

    Once I did that, I was able to get the service to start:

    2015-07-06 13_52_27-Administrator_ Command Prompt - sqlservr   -m -s sql2012

    I’m not sure what was hard here, and this is how I’ve always managed to start and stop SQL Server in single user mode from the command line. I then see the output of what is sent to the error log at the console.

    However I also searched around and found a few other ways that are easy to accomplish.

    Net Start

    I haven’t often used net start for commands, but I have a few times. In this case, I looked at BOL and found I could do this:

    2015-07-06 13_43_20-Administrator_ Command Prompt

    This is essentially what clicking "start" in the services applet or Configuration Manager does. However I can add in my "m" parameter with a slash (/) instead of a dash.

    To stop the service, I use NET STOP.

    2015-07-06 13_43_44-Administrator_ Command Prompt

    Configuration Manager

    If you run Configuration Manager, you can also add parameters. First, right click the service and get the properties. Then you want the "Startup Parameters" tab. In there, you can add a parameter in the top box, as I’ve done here.

    2015-07-06 13_44_19-SQL Server (SQL2012) Properties

    Clicking "Add" will put it in the list.

    2015-07-06 13_44_26-SQL Server (SQL2012) Properties

    When you stop the service, the next startup will have this parameter take effect.

    2015-07-06 13_44_06-Sql Server Configuration Manager

    Beware that when you start things up, the first connection that successfully logs into SQL Server will be the only one allowed. Any applications looking to connect, monitoring programs (SQL Monitor or DLM Dashboard) or other clients can take your connection, so be careful and quick.

    SQLNewBlogger

    This was really a quick writeup. I stopped my service and played for 10 minutes, ran a few searches, and took some screenshots. I would have been faster, but I wanted to document this.

    This is great practice for a skill you need rarely, but when you do, you’ll be stressed. Be sure you can start and stop SQL Server a few ways, and add parameters like trace flags and the -m for emergencies.

    References

  • Using the DAC

    Another post for me that is simple and hopefully serves as an example for people trying to get blogging as #SQLNewBloggers.

    The DAC is a really important tool for anyone managing a SQL Server. You might not use it often, but when you need it, you really need it. I’d suggest you connect to your instances one a month or so using the DAC, just to be sure you know how to do it.

    The most common reason to use the DAC is when a runaway query is consuming so many resources the user can’t connect. The DAC is guaranteed resources, so you can always connect.

    When you use SQLCMD, the -A switch lets the connection method know you want to use the DAC. The DAC only allows one connection, so only one admin can connect. This also means it’s important to disconnect quickly if you don’t need the DAC.

    To connect, I use a normal set of parameters, -S for my server and -E for Windows auth. However I then add the -A, which connects me through the DAC.

    2015-07-13 10_48_04-Command Prompt

    Once I connect, I can run any of the normal commands, I need, like rebuilding master or killing a connection.

    2015-07-13 10_48_23-SQLCMD

    Keep this as a tool in your toolbox and practice regularly.

    SQLNewBlogger

    This was a quick post that follows on from starting SQL in single user mode as well as using the DAC in SSMS. I really just took some shots as I connected from SQLCMD.

    References

    The first link I saw was from my friend, Pinal Dave.

  • Azure SQL Database – Link User to Login

    I’m writing this post as a way to help motivate the #SQLNewBloggers out there. Read the bottom for a few notes on structuring a post.

    I created a login for an Azure SQL Database, but couldn’t log in. I would get this message, which makes perfect sense.

    2015-06-23 14_52_41-Connect to Database Engine

    Just like an on-premises instance, I need to link a user to the login for access. However, unlike an on-premises SQL Server, I can’t willy-nilly change databases. If I do this:

    Use SQLServerCentral GO

    I’ll get this message.

    2015-06-23 15_00_31-SQLQuery3.sql - mhknbn2kdz.database.windows.net,1433.SQLServerCentral (jt (58))_

    I can’t switch, I need to reconnect. In this case, I use the same login (an admin level) and reconnect to a different database. This certainly can make scripts more cumbersome, and imply that your work, whether through T-SQL or PoSh, needs to include the connection strings for the correct database. In fact, I might recommend PoSh over SSMS for this reason.

    Once I’ve connected, I can use standard commands. In this case, I’ll use this code:

    — add user to SQLServerCentral database — connect to database CREATE USER sscdev FROM LOGIN sscdev; — add a role for ddl admin EXEC sp_addrolemember ‘db_ddladmin‘, ‘sscdev‘;

    Now when I click connect with my user, I see this:

    2015-06-23 15_02_22-SQLQuery4.sql - mhknbn2kdz.database.windows.net,1433.sqlservercentral (sscdev (5

    Just what I need.

    SQLNewBlogger

    This was a second post as part of the previous one. I was adding a user and login as part of a bit of work and when it didn’t work, I captured screen shots and split this part from the last one.

    Five minutes writing this one, probably no more than five minutes slower in running the code to capture the images.

    You can do this.

    References

  • Azure SQL Database – Adding a Login

    I’m writing this post as a way to help motivate the #SQLNewBloggers out there. Read the bottom for a few notes on structuring a post.

    I am trying to slowly do a little work in the Azure SQL Database world, building some skills that I can use, and I can teach you a bit more about. One of the things I needed to do lately was add a new login to my system, which isn’t intuitive in the portal.

    I did go to the Managing Databases and Logins in Azure SQL Database to get some help, but it wasn’t completely clear how to do this.

    I setup a database recently for a test project, but I wanted a different user for this database than others I have on this particular Azure SQL Server. I am using the new (2015) portal, and there didn’t seem to be a good way to add a new login, so I connected to do this in SQL. The reference below showed me the standard “CREATE LOGIN” statement I’d use with an on-premise instance, so I tried to run that.

    CREATE LOGIN sscqa WITH PASSWORD = ‘mypwd‘; GO

    I got this:

    2015-06-23 14_45_19-SQLQuery3.sql - mhknbn2kdz.database.windows.net,1433.AdventureWorks2012 (sjones

    OK, no issues. I changed the connection to the use the master database. I used the options after clicking the “Change Connection” button and put in master.

    2015-06-23 14_47_06-SQLQuery3.sql - mhknbn2kdz.database.windows.net,1433.AdventureWorks2012 (sjones

    I connected and ran the code to get this:

    2015-06-23 14_47_30-SQLQuery3.sql - mhknbn2kdz.database.windows.net,1433.master (sjones (63))_ - Mic

    I needed to not only change my database user connection, but also use the admin user I have. In this case, it’s the jt user I inherited from Jamie Thomson as part of the Hosted AdventureWorks project he started.

    Once I did that, the login was created without an issue. Now I need to link it to a user.

    SQLNewBlogger

    This took about 5 minutes to write, and 5 minute to reshoot some screen shots. The rest was really the 20 minutes I spent mucking around, researching, and reading how to do this. Hopefully this is quicker for me, and you, if you have this need.

    Anyone could write this, and I’d encourage you to write your own stories about working with an Azure database if you want to learn about the topic.

    Reference