Dot.Net and PowerShell

PS C:\Users\IBM_ADMIN> [IO.Path]::GetTempPath()

Posted in develop | Tagged , | Leave a comment

Getting exclusive access to a SQL Server database for restore


When restoring a database, one of the things you need to do is ensure that you have exclusive access to the database.  If any other users are in the database the restore will fail.


When trying to do a restore, if any other user is in the database you will see these types of error messages:


Msg 3101, Level 16, State 1, Line 1
Exclusive access could not be obtained because the database is in use.
Msg 3013, Level 16, State 1, Line 1
RESTORE DATABASE is terminating abnormally.


Getting Exclusive Access

To get exclusive access, all other connections need to be dropped or the database that they are in needs to be changed so they are not using the database you are trying to restore.  You can use sp_who2 or SSMS to see what connections are using the database you are trying to restore.

Using KILL
One option to get exclusive access is to use the KILL command to kill each connection that is using the database., but be aware of what connections you are killing and the rollback issues that may need to occur.  See this tip for more information on how to do this.

Another option is to put the database in single user mode and then do the restore.  This also does a rollback depending on the option you use, but will do all connections at once.  See this tip for more information on how to do this.

RESTORE DATABASE AdventureWorks FROM DISK = 'C:\AdventureWorks.BAK' 
Posted in sql.server | Tagged | Leave a comment

Recovering From SQL Server ‘recovery pending’ Status

Seeing a database in any state other than “online” makes me a little nervous. For one thing, it’s one of those things I don’t see often, so I have to rub a few brain cells together to remember what I did the last time. For another, there’s no guarantee that you’ll be able to get the database back online. That’s scary.

But one of our clients had three SQL Server databases in “recovery pending” state this week. Trying to bring the databases online produces these errors:


"Error: 5173, Severity: 16, State: 1. One or more files do not match the 
primary file of the database. If you are attempting to attach a database, 
retry the operation with the correct files. If this is an existing database,
the file may be corrupted and should be restored from backup."


"Error: 928, Severity: 20, State: 1: During upgrade, database raised exception 
945, severity 14, state 2, address (). Use the exception number to determine 
the cause."

The 928 error was a typical Microsoft red herring having to do with database compatibility levels and permissions. However, trying to bring the database online added a little meat to the 5173 error’s bones:

"Database [dbname] cannot be opened due to inaccessible files or insufficient 
memory or disk space. See the SQL Server errorlog for details."

And also:

"Log file [log name] does not match the primary file. It may be from 
a different database or the log may have been rebuilt previously."

I checked file permissions, memory and disk space. Everthing was kosher there. I knew that would be the case because life just isn’t that easy.

Which left the log files. These databases (along with a dozen others in the instance) had been involved in a SAN crash. They were migrated to a new disk, but performance was awful — data warehouse processes were taking 10 times longer to run than they had previously. So the client built a new drive for the logs, migrated the logs, changed the drive letter, and altered the file paths stored in the master database. Plenty of opportunities there to corrupt the log.

I had no backups to work with, so I needed to recover the databases. I put one of the db’s in emergency mode to try to run CHECKDB, but CHECKDB couldn’t access the files either.

So, on to the last resort (I’ll spare you the trial and error and get down to the solution):

1. Set the database status to emergency:


2. Put the database in multi-user mode:


3. Detach the database:

EXEC sp_detach_db '[dbname]'

4. Reattach the data file only:

EXEC sp_attach_single_file_db @dbname = '[dbname]', 
     @physname = N'[mdf path]' 

The point here is to get rid of the corrupt log and let SQL Server build a new one. Three words to the wise:

First, according to Microsoft, you should use sp_attach_single_file_db ONLY on data files detached using sp_detach_db. So don’t use the GUI — use sp_detach_db.

Second, put the database in MULTI_USER mode before detaching. SQL Server can’t build a new log if the data file is read-only. If you detach in SINGLE_USER mode, Plan B is a real pain.

Third, don’t make your DBA do this. Back up your databases.


Posted in Uncategorized | Tagged , | Leave a comment

Get the SQL Server database in the normal state

SQL Server Management Studio reports a database in “Recovery Pending” status.

USE master

Posted in Uncategorized | Tagged , | Leave a comment

SQL Connectivity Behavior

By default, the default protocol for SQL Server clients is TCP/IP. If the connection cannot be made using TCP/IP, the other enabled protocols are attempted. A shared memory connection cannot be made over a network. Use SQL Server Configuration Manager to enable or disable client protocols, and to change the order in which connection attempts are made.

Posted in develop | Tagged , | Leave a comment


Posted in tools | Tagged | Leave a comment

Vodafone 6 Ultra OTA

This is Vodafone Smart Ultra 6 official firmware package. Download from the link below and use flashing instructions found at the end of the post to install the stock ROM to your smartphone.

Vodafone Smart Ultra 6 – Download
How to flash Vodafone Smart Ultra 6 stock firmware
Follow flashing instructions available via this link.

ZTE image for VDF995


Posted in tools | Tagged , , , , | Leave a comment