Dot.Net and PowerShell

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

Posted in develop | Tagged , | Leave a comment

Getting exclusive access to a SQL Server database for restore

https://www.mssqltips.com/sqlservertutorial/82/getting-exclusive-access-to-a-sql-server-database-for-restore/

Overview

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.

Explanation

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

T-SQL

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.

SSMS


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.

Using ALTER DATABASE
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.

ALTER DATABASE AdventureWorks SET SINGLE_USER WITH ROLLBACK IMMEDIATE
GO
RESTORE DATABASE AdventureWorks FROM DISK = 'C:\AdventureWorks.BAK' 
GO
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:

First:

"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."

Second:

"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:

ALTER DATABASE [dbname] SET EMERGENCY

2. Put the database in multi-user mode:

ALTER DATABASE [dbname] SET MULTI_USER

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.

 

http://www.xtivia.com/recovering-recovery-pending-status/

 

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
ALTER DATABASE [dbname] SET OFFLINE WITH ROLLBACK IMMEDIATE
ALTER DATABASE [dbname] SET ONLINE WITH ROLLBACK IMMEDIATE

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.

https://technet.microsoft.com/en-us/library/ms190204%28v=sql.105%29.aspx

Posted in develop | Tagged , | Leave a comment

VPN

https://www.expressvpn.com/

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.

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

https://www.leakite.com/2016/11/download-vodafone-smart-ultra-6.html

ZTE image for VDF995

http://www.ztedevice.com/support/detail?id=C6FD604A845B452FA332206161CEA7BF#software

 

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