Skip to content

Instantly share code, notes, and snippets.

View tompazourek's full-sized avatar
👨‍💻
Busy

Tom Pažourek tompazourek

👨‍💻
Busy
View GitHub Profile
/* Drop all non-system stored procs */
DECLARE @name VARCHAR(128)
DECLARE @SQL VARCHAR(254)
SELECT @name = (SELECT TOP 1 [name] FROM sysobjects WHERE [type] = 'P' AND category = 0 ORDER BY [name])
WHILE @name is not null
BEGIN
SELECT @SQL = 'DROP PROCEDURE [dbo].[' + RTRIM(@name) +']'
EXEC (@SQL)
@tompazourek
tompazourek / Global_Application_Error.asax
Last active August 29, 2015 14:21
ASP.NET MVC Errors
// NOTE: ELMAH logs the errors anyway
protected void Application_Error(object sender, EventArgs e)
{
var exception = Server.GetLastError();
var httpException = exception as HttpException;
if (httpException != null)
{
switch (httpException.GetHttpCode())
<modules runAllManagedModulesForAllRequests="false">
<!-- disable authorization section -->
<remove name="UrlAuthorization" />
<!-- disable unused authentication schemes -->
<remove name="WindowsAuthentication" />
<remove name="PassportAuthentication" />
<!-- disable ACL file and directory check -->
<!-- <remove name="FileAuthorization" /> -->
<!-- We don't use ASP.NET Profiles -->
<remove name="Profile" />
BEGIN TRY
BEGIN TRANSACTION
-- statements here
COMMIT TRAN
END TRY
BEGIN CATCH
IF @@TRANCOUNT > 0
ROLLBACK TRAN
USE [master]
DECLARE @dbname SYSNAME
SET @dbname = 'DATABASENAME'
DECLARE @spid INT
SELECT @spid = MIN([spid]) FROM [master].[dbo].[sysprocesses] WHERE [dbid] = DB_ID(@dbname)
WHILE @spid IS NOT NULL
BEGIN
@tompazourek
tompazourek / AppPoolUser.sql
Created September 4, 2015 16:55
Add IIS App Pool User to SQL Server.
-- http://stackoverflow.com/a/16310139/108374
CREATE LOGIN [IIS APPPOOL\MyAppPool] FROM WINDOWS;
CREATE USER MyAppPoolUser FOR LOGIN [IIS APPPOOL\MyAppPool];
-- Disable all table constraints
ALTER TABLE MyTable NOCHECK CONSTRAINT ALL
-- Enable all table constraints
ALTER TABLE MyTable CHECK CONSTRAINT ALL
-- Disable single constraint
@tompazourek
tompazourek / RebuildAllIndexes.sql
Created July 9, 2015 09:58
Rebuild all indexes
DECLARE @TableName varchar(255)
DECLARE TableCursor CURSOR FOR
SELECT table_name FROM information_schema.tables
WHERE table_type = 'base table'
ALTER DATABASE [VoracioPlatform]
SET READ_COMMITTED_SNAPSHOT ON
GO
ALTER DATABASE [VoracioPlatform]
SET ALLOW_SNAPSHOT_ISOLATION ON
GO
set statistics time on
-- execute queries
set statistics time off
-- http://stackoverflow.com/a/11675263/108374