Sunday, November 18, 2012

Exporting and Importing Sites and App Pools

When using multiple IIS server in a Load Balanced Environment it will  be alot of work to create all you’re website twice with the same settings on each webserver. Therefor it is possible to export and import you’re configuration from one webserver to the other.

To Export the Application Pools on IIS 7 :
%windir%\system32\inetsrv\appcmd list apppool /config /xml > c:\apppools.xml
This will export all the application pools on you’re webserver, therefor you need to edit the apppools.xml and remove the application that you do not need to import for example:
  • DefaultAppPool
  • Classic .NET AppPool
  • SecurityTokenServiceApplicationPool
To import the Application Pools:
%windir%\system32\inetsrv\appcmd add apppool /in < c:\apppools.xml
All the AppPools in the xml will be created on you’re second webserver.



Command Line code for export and import site configuration

To export/import a single application pool:
%windir%\system32\inetsrv\appcmd list apppool “MyAppPool” /config /xml > c:\myapppool.xml

Import:
%windir%\system32\inetsrv\appcmd add apppool /in < c:\myapppool.xml

To export/import a single website:



C:\Windows\System32\inetsrv>appcmd list site "SmithersColombiaAnalytics" /config /xml > c:\soColmbAlty.XML


Import:



C:\Windows\System32\inetsrv>appcmd.exe add site /in < d:\import\soAustAlty.xml

 

Tuesday, September 4, 2012

Installing dlls to GAC with .net Framework 4.0



I recently faced to an issue with installing dlls to GAC with .net Framework 4.0.

It was my local development machine and .net Framework 4.0. I wanted to install a dll to GAC. But gacutil.exe was not there.

.net 4.0 GAC location C:\Windows\Microsoft.NET\assembly\GAC_MSIL


I copied gacutil.exe from my  staging server to my machine. The exe was located in “C:\Windows\Microsoft.NET\Framework\v1.1.4322”.  Then I tried to install the dll. but it returned an error saying version mismatch.

When I search for the issue, I found that gacutil.exe come with the “Microsoft Windows SDK for Windows 7 and .NET Framework 4”. I downloaded SDK from here and installed in my development server. Then copied these files from development server (C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\NETFX 4.0 Tools ) to production server. Then Tried to run gacutil –i.
    gacutil.exe
    gacutil.exe.config
    1033\gacutlrc.dll

These files can be placed any location in the machine, but need to run the gacutil - command from that location.

Remember to put gacutlrc.dll in to the same folder, otherwise your command will run wiout giving any errors, but dll won’t be in GAC.

Saturday, August 25, 2012

Get last index position of character


The function is used to find the last index position of the character in the given string

Create FUNCTION [dbo].[CharLastIndex](@SeekChars nvarchar(max),@String nvarchar(max))
RETURNS int
AS 
BEGIN   
    Declare @Index int,@startPosition int
    SET  @startPosition=0
    Select @Index= charindex(@SeekChars,@String,@startPosition)
    SET @startPosition = @Index
    While(@startPosition!=0)
    BEGIN
        SET @Index =@startPosition
        Select @startPosition = charIndex(@SeekChars,@String,@startPosition+1)
    END

RETURN @Index
END

Check given string is integer or not



Create FUNCTION [dbo].[CheckIsInt](@String nvarchar(255)) 
RETURNS bit
AS 
BEGIN   
Declare @Count int,@char nchar(1),@result bit
SET @Count=1
SET @result =0
While (@Count<=len(@String))
BEGIN
    Set @char =substring(@String,@Count,1)
    if(charindex(@char,'0123456789')=0)
        return 0
    else
        SET @result=1   
    SET    @Count =@Count + 1
END
return @result

END

Get Distinct String using SQL Server

Get distinct string between given two string

ALTER function [dbo].[GetDistinctString](@string1 varchar(max),@string2 varchar(max))
returns varchar(max)
as
begin
Set @string2 = ',' + @string2 + ','
Declare @count int,@index int,@s1Len int,@nextIndex int
Set @index=0
Set @nextIndex =1
Set @s1Len=len(@string1)
Declare @part varchar(4)

While(len(@string2)>0 and @index <= @s1Len and @nextIndex <> 0)
begin
    Set @nextIndex = charindex(',',@string1,@index)
    if @nextIndex !=0
    begin
        Set @part = substring(@string1,@index,@nextIndex - @index )
       
    end
    else
    begin
        Set @part = substring(@string1,@index,@s1Len - @index + 1)
       
    end
    --Set @string2 = replace(@string2,@part,'')
    Set @string2 = replace(@string2,','+@part+',',',')
   
    Set @index =@nextIndex+1

end
Set @string1 = @string1 + @string2
Set @s1Len =len(@string1)
return substring(@string1,0,@s1Len)

end

Get Empty Guid using SQL Function


Get Empty Guid using SQL Server

Create FUNCTION [dbo].[GetEmptyGUID]()
RETURNS UNIQUEIDENTIFIER
AS
BEGIN
RETURN SELECT CAST(CAST(0 as BINARY) AS UNIQUEIDENTIFIER)
END

Truncate Time

Function to truncate the time from the given date using SQL Server

ALTER FUNCTION [dbo].[TruncateTime]
(
@dateToConvert datetime
)
RETURNS datetime
AS
BEGIN
RETURN convert(datetime, convert(varchar(10), @dateToConvert, 101))
END