Category: Database

SQL: Microsoft Dynamics – Rebuilding a Database View Named ‘FilteredContact’

Why? Update: currently, I'm unable to rebuild this complex view due to SQL constraints. Hence,…

SQL Server: Use Profiler to Tune Database Indexes

Run Microsoft SQL Server Management Studio > Tools > SQL Server Profiler > Use the…

How to Migrate a Database to a Newer Version of Microsoft SQL Server

Get Version of new SQL server Create a sql-dump script on the old SQL server:…

T-SQL Msg 3101 Exclusive access could not be obtained because the database is in use

Symptom: Msg 3101, Level 16, State 1, Line 2Exclusive access could not be obtained because…

SQL Error Msg 3201, Level 16, State 2

Sample Error Message: Msg 3201, Level 16, State 2, Line 2Cannot open backup device '\\1.1.1.1\d$\backup\TEST_MSCRM.bak'.…

Invoke T-SQL on Multiple Servers

$computersAndCredentials=@{ 'SQL01'=@{'intranet\sql01Admin'='PASSWORD'} 'SQL02'=@{'intranet\sql02Admin'='PASSWORD'} 'SQL03'=@{'intranet\sql03Admin'='PASSWORD'} 'SQL04'=@{'intranet\sql04Admin'='PASSWORD'} } $tSql=" --Update the Setting with a new value: USE…

Microsoft Dynamics Email Router Failed to Start

Symptoms Event Log: Item 1: highest correlating event ID 26234 #26234 - The Email Router…

PowerShell: Restore SQL Database from Full and/or Differential Backups

$databaseName='BALOO_MSCRM' $newDatabaseName='BALOO_MSCRM' $dbData='mscrm' # set this value to $null for autogen defaults $dbLog='mscrm_log' # set…

Microsoft SQL Cloning Database to a Different DB Name

# User defined variables $sourceSqlServer='DEV-SQL01' $sourceDatabaseName='TEST_MSCRM' $sourceSaCredential=$(get-credential) $destinationSqlServer='DEV-SQL01' $destinationDatabaseName='Test_MSCRM' $destinationSaCredential=$(get-credential) function copyDatabase{ param( $sourceSqlServer, $sourceDatabaseName,…

Microsoft Dynamics Audit History Data Missing After Org Migration

Issue: We have recently moved some Orgs from CRM version 8.x to 9.x, and audit…

How to Add Domain Admins to SQL Server

Step 1: Right-click Start > Search > type in 'ssms.exe' > right-click Microsoft SQL Server…

SQL: Creating a Storage Report of Databases Residing within Server

Method 1: -- Get sizes of all databases from system (not real-time) WITH fs AS…

SQL: Backup Database and Purge It From SQL Server

/* Make a Final Backup of Database, Purge Its Backup and Restore History, and Remove…

PowerShell: Graceful Shutdown of MS SQL Server

import-module sqlps CD SQLSERVER:\SQL\$env:computername $sql = (get-item .).ManagedComputer # This command stops MSSQL$instanceName, SQLSERVERAGENT, SQLAGENT$instanceName,…

PowerShell: Invoke Backup SQL Database

Function to invoke SQL Backups on a Remote SQL Server: # invokeSqlBackup.ps1 # Version 0.0.1…

PowerShell: Get SQL Server Performance Counters

Version 2 # getSqlPerformanceCounter.ps1 # version 0.02 $computername='sql0003.kimconnect.com' function getSqlPerformanceCounter($server=$env:computername,$sampleInterval=10,$maxSamples=1){ $PerformanceCounterSampleSet=$result=@() $counters=@( '\Memory\Available MBytes', '\Memory\Pages/sec',…

PowerShell: Optimize SQL Server Memory & CPU Resources

# optimizeSqlServer.ps1 # Version 0.0.2 # This version deals with Memory, CPU # Future versions…

SQL: Use PowerShell to Validate if Database Exists

This function may be invoked remotely from a machine that has SQL-PS module installed. The…

SQL: Use PowerShell to Generate a Database Object From Another Object

Have you ever wondered about the prospect of automating T-SQL executions on Windows? As your…

SQL: Using PowerShell to Check if a Table, View, or Stored Procedure Exists

#Usage # set variables $sqlServer='sql-server04' $databaseName="Test_Database" $objectType='view' $objectName='[dbo].[Test_View]' $saCred=get-credential # Call function checkDatabaseObject $sqlServer $databaseName…