<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Personal Weblog of John Wood &#187; SQL Server</title>
	<atom:link href="http://www.webofwood.com/category/sql-server/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.webofwood.com</link>
	<description>Wordpress weblog of John Wood, a Database Administrator</description>
	<lastBuildDate>Thu, 29 Jul 2010 14:00:56 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Using Powershell to Set Up SQL Server Mirroring</title>
		<link>http://www.webofwood.com/2010/07/29/powershell-sqlserver-mirroring/</link>
		<comments>http://www.webofwood.com/2010/07/29/powershell-sqlserver-mirroring/#comments</comments>
		<pubDate>Thu, 29 Jul 2010 13:50:07 +0000</pubDate>
		<dc:creator>John Wood</dc:creator>
				<category><![CDATA[Powershell]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[Powershell sqlserver mirror script]]></category>

		<guid isPermaLink="false">http://www.webofwood.com/?p=123</guid>
		<description><![CDATA[Management recently decided to use database mirroring as our DR solution. Because mirroring is done at the database level and not at the server level, I had a lot, a very lot of databases to be mirrored. To make it easier I decided to cobble together a simplistic script to do this. I typically use [...]]]></description>
			<content:encoded><![CDATA[<p>Management recently decided to use database mirroring as our DR solution. Because mirroring is done at the database level and not at the server level, I had a lot, <strong><em>a very lot</em></strong> of databases to be mirrored. To make it easier I decided to cobble together a simplistic script to do this. </p>
<p>I typically use a &#8216;management&#8217; server for most of my needs and have therefore written the script to use UNC type pathing for the primary as well as mirror server. You will also notice I defaulted several of the parameters. This is handy when working on a set of servers for multiple databases.</p>
<p>I hope you find the script useful. You can also find a copy of the script at <a title="scriptinganswers.com" href="http://www.scriptinganswers.com" target="_blank">www.scriptinganswers.com</a>.</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:6127b23c-ffcb-4ec0-83a2-518000bca639" class="wlWriterEditableSmartContent">del.icio.us Tags: <a href="http://del.icio.us/popular/powershell" rel="tag">powershell</a>,<a href="http://del.icio.us/popular/sqlserver" rel="tag">sqlserver</a>,<a href="http://del.icio.us/popular/mirror" rel="tag">mirror</a></div>
<pre class="brush: ps">&lt;#
	.SYNOPSIS
		Set up an SQL Server mirrored database
	.DESCRIPTION
		Backs up a database and tlog, copies it to the destination,
		Restores the database on the mirror server, sets up the partner,
		and starts the mirror.
	.PARAMETER  database
		The name of the database to be mirrored
	.PARAMETER  SourceServer
		The name of the primary server
	.PARAMETER  SourcePath
		Local Path for the backup
	.PARAMETER  DestServer
		The name of mirror server
	.PARAMETER  DestPath
		Local path for restore file
	.EXAMPLE
		PS C:\&gt; Invoke-Mirror -database 'string value' `
			-SourceServer 'string\string' -SourcePath 'string' `
			-DestServer 'string\string' -DestPath 'string'
	.NOTES
		The SQL connections rely on Windows authentication and assumes Endpoints
		already exist. Error checking is minimal (i.e. no check is made to
		verify the recovery model is FULL).
	.AUTHOR
		John P. Wood
		07/28/2010
#&gt;
Param(
	[Parameter(Mandatory=$true)]
	[string]$database,
	[string]$SourceServer='Server1\Instance',
	[string]$SourcePath='K:\SQL Backups',
	[string]$DestServer='Server2\Instance',
	[string]$DestPath='K:\SQL Backups'
	)
[Void][System.Reflection.Assembly]::LoadWithPartialName(&quot;Microsoft.SqlServer.ConnectionInfo&quot;)
[Void][System.Reflection.Assembly]::LoadWithPartialName(&quot;Microsoft.SqlServer.SMO&quot;)
[Void][System.Reflection.Assembly]::LoadWithPartialName(&quot;Microsoft.SqlServer.SmoExtended&quot;)
Function New-SMOconnection {
    Param (
		[string]$server
	)
	$conn = New-Object Microsoft.SqlServer.Management.Common.ServerConnection($server)
	$conn.applicationName = &quot;PowerShell SMO&quot;
	$conn.StatementTimeout = 0
	$conn.Connect()
	if ($conn.IsOpen -eq $false) {
		Throw &quot;Could not connect to server $($server) for database backup of $($dbname).&quot;
	}
	$smo = New-Object Microsoft.SqlServer.Management.Smo.Server($conn)
	$smo
}
Function Invoke-SqlBackup {
	$dbbk = new-object ('Microsoft.SqlServer.Management.Smo.Backup')
	$dbbk.Action = [Microsoft.SqlServer.Management.Smo.BackupActionType]::Database
	$dbbk.BackupSetDescription = &quot;Full backup of &quot; + $database
	$dbbk.BackupSetName = $database + &quot; Backup&quot;
	$dbbk.Database = $database
	$dbbk.MediaDescription = &quot;Disk&quot;
	$device = &quot;$SourcePath\$bkpfile&quot;
	$dbbk.Devices.AddDevice($device, 'File')
	$smo = New-SMOconnection -server $SourceServer
	Try {
		$dbbk.SqlBackup($smo)
		$dbbk.Action = [Microsoft.SqlServer.Management.Smo.BackupActionType]::Log
		$dbbk.SqlBackup($smo)
		$smo.ConnectionContext.Disconnect()
	}
	Catch {
		$ex = $_.Exception
		Write-Output $ex.message
		$ex = $ex.InnerException
		while ($ex.InnerException)
		{
			Write-Output $ex.InnerException.message
			$ex = $ex.InnerException
		};
		continue
	}
	Finally {
		if ($smo.ConnectionContext.IsOpen -eq $true) {
			$smo.ConnectionContext.Disconnect()
		}
	}
}
Function Invoke-SqlRestore {
	Param([string]$filename)
	$restore = new-object Microsoft.SqlServer.Management.Smo.Restore
	$restore.Action = 'Database'
	$restore.Database = $database
	$device = &quot;$DestPath\$filename&quot;
	$restore.Devices.AddDevice($device, 'File')
    $restore.ReplaceDatabase = $true
    $restore.NoRecovery = $true
	$smo = New-SMOconnection -server $DestServer
	Try {
		$restore.SqlRestore($smo)
		$restore.Action = [Microsoft.SqlServer.Management.Smo.RestoreActionType]::Log
		$restore.FileNumber = 2
		$restore.SqlRestore($smo)
		$smo.ConnectionContext.Disconnect()
	}
	Catch {
		$ex = $_.Exception
		Write-Output $ex.message
		$ex = $ex.InnerException
		while ($ex.InnerException)
		{
			Write-Output $ex.InnerException.message
			$ex = $ex.InnerException
		};
		continue
	}
	Finally {
		if ($smo.ConnectionContext.IsOpen -eq $true) {
			$smo.ConnectionContext.Disconnect()
		}
	}
}
Function Set-Mirror {
	Param([string]$server,[string]$database,[string]$partner)
	$conn = &quot;Server=$server; Integrated Security=SSPI; Database=Master&quot;
	$cn = New-Object &quot;System.Data.SqlClient.SqlConnection&quot; $conn
	$cn.Open()
	$cmd = New-Object &quot;System.Data.SqlClient.SqlCommand&quot;
	$cmd.CommandType = [System.Data.CommandType]::Text

	$cmd.CommandText = &quot;ALTER DATABASE $database SET PARTNER = 'TCP://&quot; + $partner + &quot;:5022'&quot;
	$cmd.Connection = $cn
	$cmd.ExecuteNonQuery()
	$cn.Close()
	Trap {
		$ex = $_.Exception
		Write-Output $ex.message
		$ex = $ex.InnerException
		while ($ex.InnerException)
		{
			Write-Output $ex.InnerException.message
			$ex = $ex.InnerException
		};
		continue
	}
}
$srcUNC = Join-Path &quot;\\$($SourceServer.Split('\\')[0])&quot; $($SourcePath.Replace(':','$'))
if (-not(Test-Path $srcUNC)) { New-Item $srcUNC -ItemType directory | Out-Null}
$destUNC = Join-Path &quot;\\$($DestServer.Split('\\')[0])&quot; $($DestPath.Replace(':','$'))
if (-not(Test-Path $destUNC)) { New-Item $destUNC -ItemType directory | Out-Null}
$bkpfile = $($SourceServer.Replace(&quot;\&quot;, &quot;$&quot;)) + &quot;_&quot; + $database + &quot;_FULL_&quot; + $(get-date -format yyyyMMdd-HHmmss) + &quot;.bak&quot;
Invoke-SqlBackup
Copy-Item $(Join-Path $srcUNC $bkpfile) -Destination $destUNC -Verbose
Invoke-SqlRestore -filename $bkpfile
# Establish Mirroring from the mirrored database
Set-Mirror -server $DestServer -database $database -partner $($SourceServer.Split('\\')[0])
# Start the mirror
Set-Mirror -server $SourceServer -database $database -partner $($DestServer.Split('\\')[0])</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.webofwood.com/2010/07/29/powershell-sqlserver-mirroring/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cycle Those SQL Server Logs</title>
		<link>http://www.webofwood.com/2010/02/15/cycle-those-sql-server-logs/</link>
		<comments>http://www.webofwood.com/2010/02/15/cycle-those-sql-server-logs/#comments</comments>
		<pubDate>Mon, 15 Feb 2010 21:21:04 +0000</pubDate>
		<dc:creator>John Wood</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Powershell]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[errorlog]]></category>
		<category><![CDATA[schedule]]></category>
		<category><![CDATA[script]]></category>

		<guid isPermaLink="false">http://www.webofwood.com/?p=62</guid>
		<description><![CDATA[Donâ€™t you just hate it when you open one of your server logs in Management Studio and then you have to wait forever to review it because it never stops reading? Iâ€™ve done it enough times and decided to put an end to it or at least greatly reduce the incidence. Using Powershell and a [...]]]></description>
			<content:encoded><![CDATA[<p>Donâ€™t you just hate it when you open one of your server logs in Management Studio and then you have to wait forever to review it because it never stops reading? Iâ€™ve done it enough times and decided to put an end to it or at least greatly reduce the incidence.</p>
<p>Using Powershell and a simple script to execute Sp_Cycle_Errorlog, I now have a weekly, Windows scheduled task which executes the sproc to cycle the logs for all my SQL Servers.</p>
<pre class="brush: ps">foreach ($svr in get-content D:\Scripts\Servers.TXT ){
    $svr
    Invoke-Expression 'SQLCMD -E -S $svr -Q "Exec Sp_Cycle_Errorlog"' | Out-Null
	}</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.webofwood.com/2010/02/15/cycle-those-sql-server-logs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Linked Server 64bit Deficiency</title>
		<link>http://www.webofwood.com/2009/08/07/linked_server_64bit/</link>
		<comments>http://www.webofwood.com/2009/08/07/linked_server_64bit/#comments</comments>
		<pubDate>Fri, 07 Aug 2009 17:00:41 +0000</pubDate>
		<dc:creator>Woody</dc:creator>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[2000]]></category>
		<category><![CDATA[2005]]></category>
		<category><![CDATA[32bit]]></category>
		<category><![CDATA[64bit]]></category>
		<category><![CDATA[linked server]]></category>
		<category><![CDATA[sproc]]></category>

		<guid isPermaLink="false">http://www.webofwood.com/2009/08/07/create-linked-server-view-of-sql-server-2000-32bit-on-64bit-sql-server-2005/</guid>
		<description><![CDATA[First off, I need to give recognition to Joel Mansford for his blog which gave me the answer to my problem. Connecting SQL Server 2005 x64 to SQL Server 7 (32bit) as a linked server!? After creating a linked server on a 64bit SQL Server 2005 instance, I then needed to create a view which [...]]]></description>
			<content:encoded><![CDATA[<p>First off, I need to give recognition to Joel Mansford for his blog which gave me the answer to my problem.<br />
<a href="http://joelmansford.wordpress.com/2007/08/10/connecting-sql-server-2005-x64-to-sql-server-7-32bit-as-a-linked-server/">Connecting SQL Server 2005 x64 to SQL Server 7 (32bit) as a linked server!? </a></p>
<p>After creating a linked server on a 64bit SQL Server 2005 instance, I then needed to create a view which referenced the linked server. The linked server is a SQL Server 2000 32bit instance. However, when I tried to create the view, I got this error:Â  <em>Cannot obtain the schema rowset &#8220;DBSCHEMA_TABLES_INFO&#8221; for OLE DB provider &#8220;SQLNCLI&#8221;.</em></p>
<p>This really proved to be a conundrum because I had just recently created the same linked server and view on another SQL 2005 instance. However, I had not yet connected the fact the 2005 instance was 32bit as opposed to the one I was now working on, which is 64bit.</p>
<p>I wrestled with it being a permissions issue for a while but ruled that out when I could not create the view even while using a domain admin account having authority of all the instances. A search on Google, using the above mentioned error message, turned up Joel&#8217;s blog. His specific problem was relative to SQL Server 7 but the answer applied to SQL Server 2000 also. He had found the original post of the ultimate solution and was good enough to include it in his blog which I have an excerpt here.</p>
<blockquote><p>I found an extremely helpful post by Marek Adamczuk at <a href="http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=62887&amp;SiteID=1">http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=62887&amp;SiteID=1</a>. MarekÂ  explains the 32-bit editions are missing a stored procedure on the master database called <strong>sp_tables_info_rowset_64.</strong></p>
<p>Marekâ€™s solution is to create a wrapper on the master database as follows (his code not mine):</p>
<pre class="brush: sql">create procedure sp_tables_info_rowset_64
    @table_name sysname,
    @table_schema sysname = null,
    @table_type nvarchar(255) = null
as
declare @Result int set @Result = 0
exec @Result = sp_tables_info_rowset
    @table_name,
    @table_schema,
    @table_type</pre>
</blockquote>
<p>It would appear the existing sproc does the same thing but just needs to be referenced using the 64bit name. Kudos to both Joel and to Marek for making this solution available!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.webofwood.com/2009/08/07/linked_server_64bit/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>eHarmony spurns Microsoft, finds match with Oracle 10g</title>
		<link>http://www.webofwood.com/2007/08/28/eharmony-spurns-microsoft-finds-match-with-oracle-10g/</link>
		<comments>http://www.webofwood.com/2007/08/28/eharmony-spurns-microsoft-finds-match-with-oracle-10g/#comments</comments>
		<pubDate>Tue, 28 Aug 2007 18:15:01 +0000</pubDate>
		<dc:creator>Woody</dc:creator>
				<category><![CDATA[Oracle]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Tech of Interest]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.webofwood.com/2007/08/28/eharmony-spurns-microsoft-finds-match-with-oracle-10g/</guid>
		<description><![CDATA[eHarmony&#8217;s Vice President of Technology, Mark Douglas, cites SQL Server&#8217;s row locking mechanics as the biggest detractor. It appears thisÂ was a major roadblock to scaling their application enough to accommodate their fast growth.Â Find out more from the entire article here&#8230; eHarmony spurns Microsoft, finds match with Oracle 10g]]></description>
			<content:encoded><![CDATA[<p>eHarmony&#8217;s Vice President of Technology, Mark Douglas, cites SQL Server&#8217;s row locking mechanics as the biggest detractor. It appears thisÂ was a major roadblock to scaling their application enough to accommodate their fast growth.Â Find out more from the entire article here&#8230;</p>
<p><a href="http://searchoracle.techtarget.com/originalContent/0,289142,sid41_gci1269811,00.html?track=NL-333&amp;ad=600149&amp;asrc=EM_NLN_2073559&amp;uid=655725">eHarmony spurns Microsoft, finds match with Oracle 10g</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.webofwood.com/2007/08/28/eharmony-spurns-microsoft-finds-match-with-oracle-10g/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Keeping Your SQL Server Databases Defragmented With Diskeeper</title>
		<link>http://www.webofwood.com/2007/05/23/defrag-sql-server-databases/</link>
		<comments>http://www.webofwood.com/2007/05/23/defrag-sql-server-databases/#comments</comments>
		<pubDate>Wed, 23 May 2007 14:05:27 +0000</pubDate>
		<dc:creator>Woody</dc:creator>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Tech of Interest]]></category>

		<guid isPermaLink="false">http://www.webofwood.com/2007/05/23/keeping-your-sql-server-databases-defragmented-with-diskeeper-updated/</guid>
		<description><![CDATA[At my organization I am the principal Oracle DBA but recently had toÂ absorb more SQL Server responsibility.Â As Murphy&#8217;sÂ Law would have it; no sooner do I get responsibility for aÂ specific technology I am new to, but the you-know-what hit theÂ fan. To make a long story short, I have to really dive [...]]]></description>
			<content:encoded><![CDATA[<p>At my organization I am the principal Oracle DBA but recently had toÂ absorb more SQL Server responsibility.Â As Murphy&#8217;sÂ Law would have it; no sooner do I get responsibility for aÂ specific technology I am new to, but the you-know-what hit theÂ fan. To make a long story short, I have to really dive in to extensive reading and research to try and alleviate some dire performance issues .Â While setting up some new RSS captures I came across this recent article which may just prove to be of enormous benefit.Â I happen to have used Diskeeper on my personal home system for years and have always been incredibly satisfied with it.Â </p>
<blockquote><p>Physical file fragmentation can hinder SQL Server&#8217;s performance. Learn how Diskeeper can help resolve this problem. By Howard Butler Sr. and Michael Materie.</p></blockquote>
<p>Source: <a href="http://www.sql-server-performance.com/absolutenm/templates/?a=2671&amp;z=2">Keeping Your SQL Server Databases Defragmented With Diskeeper (Updated)</a><br />
Originally published on 5/17/2007 4:11 PM</p>
]]></content:encoded>
			<wfw:commentRss>http://www.webofwood.com/2007/05/23/defrag-sql-server-databases/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
