Saturday, January 30, 2010

SQL Server 2008 System Views Map

Microsoft has published SQL Server 2008 System View map in .pdf and .xps file format. It's a must for SQL Server DBA. Get the map from here.

Friday, January 22, 2010

Cannot drop the database 'MyDatabase' because it is being used for replication. [SQLSTATE 42000] (Error 3724)

I wanted to drop and restore a database which I restored couple days ago in a test environment. The same db in production is the publisher and there are objects in transactional replication. I was asked to restore the new backup. However drop database returned the error message in the subject line and did not drop the db. Little bit of searching and I found out that the stored procedure can be used to remove the replication prior to dropping the database in test environment. So I connected to my test server and executed following statements in the order.

1. USE MASTER EXEC dbo.sp_removedbreplication @dbname = 'MyDatabase'
2. USE MASTER DROP DATABASE MyDatabase

It worked and I was able to drop and restore the latest backup to the test environment.

Do not run this in production since it will remove the replication from your production publisher.

HTH,

Friday, January 15, 2010

SQL Server SA Login Disabled and Can Not Login To Server

I needed to fix the login issue on newly installed SQL Server 2008 developer edition for a developer who is just starting to work. The tech who prepared the workstations forgot to add the local admin and the AD user account and he was out of the office. So even with the local administrator account no one can log in to SQL Server. Thanks to new security settings of SQL Server 2008. I did a little research and found out the solution. Here is the list of actions for the solution. First open the SQL Server Configuration Manager.

1. Stop SQL Server Service.
2. Double click on SQL Server service and goto advanced tab.
3. add -m; to the beginning of Startup Parameters
4. Start SQL Server Service
5. Open command prompt and connect to your the server using SQLCMD
6. Create a log in (CREATE LOGIN BillGates WITH PASSWORD = 'password')
7. Now add the log in to sysadmin group (EXEC sp_addsrvrolemember 'BillGates','sysadmin')
8. Remember you need to issue GO command to execute the commands.
9. Once you created the login and add it to sysadmin role go to SQL Server Configuration Manager.
10. Stop SQL Server service.
11. Remove -m; from startup parameters.
12. Start SQL Server Service and login with the user that you just created.
13. Now you have sysadmin rights.

HTH,

Bulent