jueves, 28 de julio de 2016

How To Repair A Suspect Database In MSSQL

Issue
You have a database in MS SQL that is tagged as (suspect) and you are unable to connect to the database.

Possible Causes
  • The database could have become corrupted.
  • There is not enough space available for the SQL Server to recover the database during startup.
  • The database cannot be opened due to inaccessible files or insufficient memory or disk space.
  • The database files are being held by operating system, third party backup software etc.
  • There was an unexpected SQL Server Shutdown, power failure or a hardware failure.
Resolution
These steps require you to have Microsoft SQL Server Management Studio installed on your computer.  If you do not have this installed please follow the steps outlined in the following article: How To Connect To Your MS SQL Database

  1. Open Microsoft SQL Server Management Studio and connect to your database
  2. Click the New Query button
  3. Paste the following SQL script into your New Query page replacing [YourDatabase] with the name of your database.
    EXEC sp_resetstatus [YourDatabase];
    ALTER DATABASE [YourDatabase] SET EMERGENCY
    DBCC checkdb([YourDatabase])
    ALTER DATABASE [YourDatabase] SET SINGLE_USER WITH ROLLBACK IMMEDIATE
    DBCC CheckDB ([YourDatabase], REPAIR_ALLOW_DATA_LOSS)
    ALTER DATABASE [YourDatabase] SET MULTI_USER
  4. Click Execute
Your database should no longer be tagged as (suspect) and you should be able to access it.

miércoles, 27 de julio de 2016

Powershell: List all IIS WebApplications (.net version, state, identity)

try{
Import-Module WebAdministration
Get-WebApplication

$webapps = Get-WebApplication
$list = @()
foreach ($webapp in get-childitem IIS:\AppPools\)
{
$name = "IIS:\AppPools\" + $webapp.name
$item = @{}

$item.WebAppName = $webapp.name
$item.Version = (Get-ItemProperty $name managedRuntimeVersion).Value
$item.State = (Get-WebAppPoolState -Name $webapp.name).Value
$item.UserIdentityType = $webapp.processModel.identityType
$item.Username = $webapp.processModel.userName
$item.Password = $webapp.processModel.password

$obj = New-Object PSObject -Property $item
$list += $obj
}

$list | Format-Table -a -Property "WebAppName", "Version", "State", "UserIdentityType", "Username", "Password"

}catch
{
$ExceptionMessage = "Error in Line: " + $_.Exception.Line + ". " + $_.Exception.GetType().FullName + ": " + $_.Exception.Message + " Stacktrace: " + $_.Exception.StackTrace
$ExceptionMessage
}

martes, 19 de julio de 2016

SQL Server Scripts

http://www.techbrothersit.com/search/label/SQL%20Server%20Scripts

Migración de dominio para SQL Server

Can I move SQL Server to another domain?

https://blogs.technet.microsoft.com/mdegre/2011/06/24/can-i-move-sql-server-to-another-domain/

Migrating SQL Server to New domain


http://social.technet.microsoft.com/wiki/contents/articles/24960.migrating-sql-server-to-new-domain.aspx

Migrating a SQL Cluster across Domains

https://blogs.technet.microsoft.com/bpaulblog/2013/01/27/migrating-a-sql-cluster-across-domains/