Translate

Thursday, January 30, 2014

SQL - List Last Database Backup Date

There is one server with a bunch of databases with some being backed up. I needed to see which ones were being backed up.

Here is the script I used:

Select dtb.name as [Database Name], (select max(backup_finish_date) from msdb..backupset 
where type = 'D' and database_name = dtb.name
) AS [Last Database Backup Date] ,
(select max(backup_finish_date) from msdb..backupset 
where type = 'L' and database_name = dtb.name
) AS [Last Log Backup Date] 
FROM
master.dbo.sysdatabases AS dtb

Monday, January 27, 2014

Backup Nexus Tablet

I figured that if I'm going to be using my tablet for testing out applications then I should back it up before I do anything on it. It was easy to do using the Android SDK.
You will also need to get the Nexus device drivers from ASUS.
Once you've download all of this use the Android Debug Bridge to backup your Nexus.

Here are the sites I used for instructions:
Tech Entice
How-To Geek
Transformer Forums
Android Heat
How to install Nexus 7 drivers on Windows

Monday, January 13, 2014

SQL - List All Triggers In A Database

I needed to get a list of all of the triggers in a database. This is the script that I used:

select sysT.name as [Table Name], sysO.name as [Trigger Name], sysM.definition as [Trigger Script] from  sys.tables sysT
inner join sys.objects sysO on sysT.object_id = sysO.parent_object_id
inner join sys.sql_modules sysM on sysO.object_id = sysM.object_id 
where sysO.type ='TR'

Sunday, January 12, 2014

SharePoint 2013 - First Deployment Problems

Set up a SharePoint 2013 server on a Windows 8 virtual machine.
First issue - the VM was set up with dynamic memory allocation. Don't use dynamic memory allocation with a SharePoint VM!

Next issue. You have to run IE as an administrator to go to the SharePoint Central Administration site. If you don't you will get in to the site but you will be missing some functionality such as "Manage services on a server" or you will get "Sorry, this site hasn't been shared with you" messages.

The biggest problem that I had was with the Distributed Cache. Symptoms were: "Cannot start service AppFabricCachingService ..." when executing Start-CacheCluster command. I tried a lot of "solutions" that I found on the web to get the AppFabric Caching Service to start but nothing worked. Finally found the solution to my problem here. Here's what worked for me:
Run PowerShell as an administrator.
Added the SharePoint snap-in to the PowerShell.
Run Remove-SPDistributedCacheServiceInstance on all servers in the farm.
Create a PowerShell file with the following code:

$SPFarm = Get-SPFarm
$cacheClusterName = "SPDistributedCacheCluster_" + $SPFarm.Id.ToString()
$cacheClusterManager = [Microsoft.SharePoint.DistributedCaching.Utilities.SPDistributedCacheClusterInfoManager]::Local
$cacheClusterInfo = $cacheClusterManager.GetSPDistributedCacheClusterInfo($cacheClusterName);
$instanceName ="SPDistributedCacheService Name=AppFabricCachingService"
$serviceInstance = Get-SPServiceInstance | ? {($_.Service.Tostring()) -eq $instanceName -and ($_.Server.Name) -eq $env:computername}
if([System.String]::IsNullOrEmpty($cacheClusterInfo.CacheHostsInfoCollection))
{
#here's the key. we can't provision, unprovision, start, or stop a Cache Service because we still have a Cache Service that have no server attached 
 $serviceInstance.Delete()
Add-SPDistributedCacheServiceInstance
$cacheClusterInfo.CacheHostsInfoCollection 
}

Execute the PowerShell file on all servers using ".\" in front of the name.
Run Add-SPDistributedCacheServiceInstance on all servers.
In Central Administration confirm that the Distributed Cache Service has been started.
If this didn't work, retrace your steps.
See: Manage the Distributed Cache service in SharePoint Server 2013

Thursday, January 2, 2014

Nexus 7 Will Not Start

So, I dropped my Nexus 7. It was in a case, fell maybe 3 feet, and would not start after the fall. I did some research and figured out that it was most likely, and hopefully, caused by a loose battery connector. Following instructions that I found on YouTube, I opened it up and sure enoughh the connector was loose.

Tuesday, December 24, 2013

SQL - Recover System Databases

  So we had one of those unfortunate things happen that you hope never happens - our SQL server database drive died. Not the drive running SQL, the drive that held the databases. Luckily we had backups of the databases. The drive was repaired but the drive also held the SQL system tables. Without the system tables SQL server will not run. I had the backups, the BAK files for the system tables, but to restore them you need something to restore them to.
  To recover the five system databases that I needed, master, model, msdb, tempdb, and distribution, I used another database server. I created five databases and restored the backups to the newly created databases. Then I copied the database files, the MDFs and LDFs, to the location that my crashed server was expecting to find them and renamed them to the file names that I knew the server would be looking for. When everything was in place I clicked start on the sql service in the server manager and the server started!
  The next day was spent recovering around forty databases. The databases were listed in SQL Server Management Studio (SSMS) but remember because of the crash there were no database files. For each one I used SSMS to create a new database and rename the database file, the MDFs and LDFs, to the names that the server was expecting. Then using SSMS I restored the backup.

Friday, December 13, 2013

TSQL - Dynamic Update

In a database I needed to search every table that began with 'afx' and find any date field that could be set to NULL and replace any dates that were 1/1/1900 with NULL. Also, the fields couldn't be 'date_from' or 'date_to'. I did a TSQL query to search all tables and fieds and found 83 fields that needed to be changed. This was far too many to do idividualy so I wrote a script based off of my original search to do it.

Here is the TSQL I used:

Declare @TN as varchar(200), @CN as varchar(200), @myValue varchar(30), @SQL as nvarchar(1000)
Declare myCursor Cursor For
Select T.Table_Name, C.Column_Name
From INFORMATION_SCHEMA.TABLES T Inner Join INFORMATION_SCHEMA.COLUMNS C
On T.TABLE_NAME like 'afx%' and T.Table_Schema = C.Table_Schema And T.Table_Name = C.Table_Name
and c.Column_Name <> 'date_from' and c.Column_Name <> 'date_to' and C.IS_NULLABLE = 'YES'
And C.Data_Type = 'datetime'
Open myCursor
Fetch Next From myCursor Into @TN, @CN
While @@Fetch_Status <> -1
Begin
Set @SQL = N'Update ' + @TN + ' set ' + @CN + ' = NULL Where [' + @CN + '] = ''1/1/1900'''
Exec sp_executesql @SQL
Fetch Next From myCursor Into @TN, @CN
End
Close myCursor
Deallocate myCursor