Posted on Leave a comment

iis restart

REM ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
REM
REM Use this batch file to start IIS web sites when the server is started. To use, ensure that all following steps have been followed.
REM 1. Place this as a batch file on the server ( C:StartWebsites.bat )
REM 2. Edit the startup group policy setting for the local machine
REM PATH : ( Group Policy Object Editor – Local ComputerPolicy – Computer Configuration – Windows Settings – Scripts – Startup)
REM 3. Add a script with the path to the batch file as the script name ( Script Name: C:StartWebsites.bat )
REM
REM ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
REM CScript Host is required to use IIS command line tools
cscript.exe //H:CScript

REM Start web sites

REM web sites
iisweb /start wiki
iisweb /start development

REM Reset default scripting host to WScript in case anything else depends on it.
cscript.exe //H:WScript

Posted on Leave a comment

Windows Platform FIPS Error

Pass this on to your folks if they get the following error in a asp.net app on the development server:

“This implementation is not part of the Windows Platform FIPS validated cryptographic algorithms”

Have your developer go into the web config and move the “sessionState” tag to just under the tag and make sure the sessionState is uncommented.

To this point I still only have speculation as to what changed on the server that now is causing this error. Most likely was a setting that changed as part of a security update.

Posted on Leave a comment

Encrypting web.config Sections

1. First, add following to web.config within the container

---------------------BEGIN: configProtectedData ---------------------

---------------------END: configProtectedData ---------------------


2. Below is an example .bat or .cmd file for encrypting sensitive sections of the web.config for a given .NET web application. Change the {PATH} to the physical path to the web application's folder.

---------------------BEGIN:  encrypt.cmd ---------------------
@echo off

REM *********************************************************
REM ** APP_PATH
REM ** Change {PATH} below to path of physical location where
REM ** application is installed
REM **
REM ** ASP_PATH
REM ** Location of ASP.NET framework
REM *********************************************************
SET APP_PATH="{PATH}"
SET ASP_PATH=C:WINDOWSMicrosoft.NETFrameworkv2.0.50727aspnet_regiis.exe
SET ASP_OPT=-pef
SET ASP_PROV="MY_PROVIDER"

%ASP_PATH% %ASP_OPT% "connectionStrings"

%APP_PATH% -prov %ASP_PROV%

pause
---------------------END: encrypt.cmd ---------------------

A complete walkthrough for this, including information on key stores is available here:

http://msdn.microsoft.com/en-us/library/2w117ede.aspx

Posted on Leave a comment

Managing Key Store

———————BEGIN: create_keystore.cmd ———————
@echo off
REM *********************************************************
REM ** ASP_PATH
REM ** Location of ASP.NET framework
REM **
REM ** Warning: keep the exported key in a safe place
REM ** you will not be able to decrypt data using
REM ** a recreated keystore even by same name
REM *********************************************************
SET ASP_PATH=C:WINDOWSMicrosoft.NETFrameworkv2.0.50727aspnet_regiis.exe
REM To Delete Key store
REM %ASP_PATH% -pz “MY_KEYS”

REM To Create key store
%ASP_PATH% -pc “MY_KEYS” -exp

REM To grant access to key store by ASP.NET application service
%ASP_PATH% -pa “MY_KEYS” “NT AUTHORITYNETWORK SERVICE”

REM To Export key store
%ASP_PATH% -px “MY_KEYS” “d:tempcryptoMY_KEYS.xml” -pri

———————END: create_keystore.cmd ———————

———————BEGIN: import_keystore.cmd ———————

@echo off
REM *********************************************************
REM **
REM ** ASP_PATH
REM ** Location of ASP.NET framework
REM *********************************************************
SET ASP_PATH=C:WINDOWSMicrosoft.NETFrameworkv2.0.50727aspnet_regiis.exe

REM To Delete Key store
%ASP_PATH% -pz “MY_KEYS”

REM To Import Key Store
%ASP_PATH% -pi “MY_KEYS” “d:tempcrypto375CSPTS_KEYS.xml”

REM To grant access to key store by ASP.NET application service
%ASP_PATH% -pa “MY_KEYS” “NT AUTHORITYNETWORK SERVICE”

———————END: import_keystore.cmd ———————

A complete walkthrough for this, including information on key stores is available here:

http://msdn.microsoft.com/en-us/library/2w117ede.aspx

Posted on Leave a comment

setmetabase UploadReadAheadSize

‘cscript setmetabase.vbs

‘set vdirObj=GetObject(“IIS://localhost/W3svc/1/ROOT”)
‘set vdirObj=GetObject(“IIS://localhost/W3SVC/1/Root/rapid/projects/proj1”)
‘set vdirObj=GetObject(“IIS://localhost/W3SVC/1/Root/rapid/projects/proj_Prototype”)
set vdirObj=GetObject(“IIS://localhost/W3SVC/1/Root/rapid/projects/proj2”)

‘ Print out the current value of some properties:
WScript.Echo “UploadReadAheadSize Before: ” & vdirObj.UploadReadAheadSize

‘ Set some properties:
‘ default is 49152
‘vdirObj.Put “UploadReadAheadSize”, 1024000

‘ Save the property changes in the metabase:
‘vdirObj.SetInfo
‘WScript.Echo “UploadReadAheadSize After: ” & vdirObj.UploadReadAheadSize

Posted on Leave a comment

Clearing out security log

If you get a message ‘security log is full’, can take the following steps….

1. log in as administrator

2. right-click ‘my computer’ icon and select ‘manage’

3. in the computer management window, expand ‘system tools’, then expand ‘event viewer’

4. select the ‘security’ entry

5. from the computer management window menu, select ‘action’, then ‘clear all events’

6. click ‘yes’ to save a copy of the log, or ‘no’ to clear the log completely

Posted on Leave a comment

Create ap_developer and ap_user Roles

USE model
GO

———————————
— ap_developer
———————————

DECLARE @RoleName sysname
set @RoleName = N’ap_developer’
IF EXISTS (SELECT * FROM sys.database_principals WHERE name = @RoleName AND type = ‘R’)
Begin
DECLARE @RoleMemberName sysname
DECLARE Member_Cursor CURSOR FOR
select [name]
from dbo.sysusers
where uid in (
select member_principal_id
from sys.database_role_members
where role_principal_id in (
select principal_id
FROM sys.database_principals where [name] = @RoleName AND type = ‘R’ ))
OPEN Member_Cursor;
FETCH NEXT FROM Member_Cursor
into @RoleMemberName
WHILE @@FETCH_STATUS = 0
BEGIN
exec sp_droprolemember @rolename=@RoleName, @membername= @RoleMemberName
FETCH NEXT FROM Member_Cursor
into @RoleMemberName
END;
CLOSE Member_Cursor;
DEALLOCATE Member_Cursor;
End
GO

IF EXISTS (SELECT * FROM sys.database_principals WHERE name = N’ap_developer’ AND type = ‘R’)
DROP ROLE [ap_developer]
GO

IF EXISTS (SELECT * FROM sys.database_principals WHERE name = N’ap_developer’ AND type = ‘A’)
DROP APPLICATION ROLE [ap_developer]
GO

CREATE ROLE [ap_developer] AUTHORIZATION [dbo]
GO

EXEC sp_addrolemember N’db_datareader’, N’ap_developer’
EXEC sp_addrolemember N’db_datawriter’, N’ap_developer’
GRANT CONTROL ON SCHEMA::[dbo] TO [ap_developer]
GRANT VIEW DEFINITION TO [ap_developer]
GRANT CREATE PROCEDURE TO [ap_developer]
GRANT EXECUTE TO [ap_developer]
GO

———————————
— ap_user
———————————
DECLARE @RoleName sysname
set @RoleName = N’ap_user’
IF EXISTS (SELECT * FROM sys.database_principals WHERE name = @RoleName AND type = ‘R’)
Begin
DECLARE @RoleMemberName sysname
DECLARE Member_Cursor CURSOR FOR
select [name]
from dbo.sysusers
where uid in (
select member_principal_id
from sys.database_role_members
where role_principal_id in (
select principal_id
FROM sys.database_principals where [name] = @RoleName AND type = ‘R’ ))
OPEN Member_Cursor;
FETCH NEXT FROM Member_Cursor
into @RoleMemberName
WHILE @@FETCH_STATUS = 0
BEGIN
exec sp_droprolemember @rolename=@RoleName, @membername= @RoleMemberName
FETCH NEXT FROM Member_Cursor
into @RoleMemberName
END;
CLOSE Member_Cursor;
DEALLOCATE Member_Cursor;
End
GO

IF EXISTS (SELECT * FROM sys.database_principals WHERE name = N’ap_user’ AND type = ‘R’)
DROP ROLE [ap_user]
GO

IF EXISTS (SELECT * FROM sys.database_principals WHERE name = N’ap_user’ AND type = ‘A’)
DROP APPLICATION ROLE [ap_user]
GO

CREATE ROLE [ap_user] AUTHORIZATION [dbo]
GO

EXEC sp_addrolemember N’db_datareader’, N’ap_user’
EXEC sp_addrolemember N’db_datawriter’, N’ap_user’
GRANT VIEW DEFINITION TO [ap_user]
GRANT EXECUTE TO [ap_user]
GO

/**********
IF EXISTS (SELECT * FROM sys.database_principals WHERE name = N’jmolsen’)
DROP USER [jmolsen]
GO
CREATE USER [jmolsen] FOR LOGIN [jmolsen] WITH DEFAULT_SCHEMA=[dbo]
GO

EXEC sp_addrolemember N’ap_developer’, N’jmolsen’
GO
************/

Posted on Leave a comment

Using ROW_NUMBER()

From SQL Server 2005 Books Online:

The following example returns rows with numbers 50 to 60 inclusive in the order of the OrderDate.

USE AdventureWorks;
GO

WITH OrderedOrders AS
(
SELECT SalesOrderID
, OrderDate
, ROW_NUMBER() OVER (ORDER BY OrderDate) AS ‘RowNumber’
FROM Sales.SalesOrderHeader
)

SELECT *
FROM OrderedOrders
WHERE RowNumber BETWEEN 50 AND 60;

Posted on Leave a comment

Default Database

/***********************************************
* This gives users a dummy default database
* in order to prevent them from:
* 1) having ‘master’ as a default database
* 2) not being able to connect to the server
* because their default database has been
* dropped, recreated, or restored
***********************************************/

USE master
GO

IF NOT EXISTS ( SELECT TOP 1 1 FROM sysdatabases WHERE name = ‘uno’ )
BEGIN
CREATE DATABASE [uno]
END
GO

ALTER DATABASE [uno] SET READ_WRITE
GO

USE uno
GO

GRANT SELECT TO [public]
GO

DECLARE @name sysname
, @sql nvarchar(max)

DECLARE login_cur CURSOR FAST_FORWARD FOR
SELECT name
FROM master..syslogins WITH (NOLOCK)
WHERE upper(name) LIKE ‘%’

OPEN login_cur

FETCH login_cur INTO @name

WHILE @@FETCH_STATUS = 0
BEGIN
SET @sql = ‘IF NOT EXISTS ( SELECT TOP 1 1 FROM sysusers WHERE name = ”’ + @name + ”’ ) ‘
SET @sql = @sql + ‘CREATE USER [‘ + @name + ‘] FOR LOGIN [‘ + @name + ‘] WITH DEFAULT_SCHEMA=[dbo];’
EXEC sp_executesql @sql
SET @sql = ‘ALTER LOGIN [‘ + @name + ‘] WITH DEFAULT_DATABASE=[uno];’
EXEC sp_executesql @sql
FETCH login_cur INTO @name
END

CLOSE login_cur
DEALLOCATE login_cur
GO

–ALTER DATABASE [uno] SET READ_ONLY
–GO

Posted on Leave a comment

Drop all constraints (PKs & FKs) and Indexes

DECLARE @objs TABLE ( id int identity(1,1), cmd nvarchar(4000), srt tinyint )
DECLARE @id int
, @cmd nvarchar(4000)

INSERT INTO @objs (cmd,srt)
SELECT 'DROP INDEX [' + A.name + '] ON [' + + SCHEMA_NAME(B.schema_id) + + '].[' + B.name + ']'
, 1
FROM sys.indexes A
INNER JOIN sys.objects B
ON A.object_id = B.object_id
WHERE A.is_primary_key = 0
AND A.is_unique_constraint = 0
AND B.type = 'U'
AND A.name IS NOT NULL
UNION
SELECT 'ALTER TABLE [' + + SCHEMA_NAME(B.schema_id) + + '].[' + B.name + '] DROP CONSTRAINT [' + A.name + ']'
, 2
FROM sys.objects A
INNER JOIN sys.objects B
ON A.parent_object_id = B.object_id
WHERE A.type = 'PK'
OR A.name IN ( 'PK_deemed_raiv','PK_driverchecklog')
ORDER BY 2

SELECT @id = max(id) FROM @objs

WHILE @id > 0
BEGIN
SELECT @cmd = cmd FROM @objs WHERE id = @id
EXEC sp_executesql @cmd
SET @id = @id - 1
END
GO