среда, 22 июля 2020 г.

Вывод длинной строки в nvarchar

Процедура, позволяющая вывести очень длинный текст переменной nvarchar. Полезно в случаях, когда переменная используется для перекладки динамического кода.

ALTER PROCEDURE [dbo].[Print_Unlimited]
    @String NVARCHAR(MAX)
AS

BEGIN

    BEGIN TRY
    ---------------------------------------------------------------------------------

    DECLARE @CurrentEnd BIGINT; /* track the length of the next substring */
    DECLARE @Offset TINYINT; /* tracks the amount of offset needed */
    SET @String = replace(replace(@String, CHAR(13) + CHAR(10), CHAR(10)), CHAR(13), CHAR(10))

    WHILE LEN(@String) > 1
    BEGIN
        IF CHARINDEX(CHAR(10), @String) BETWEEN 1 AND 4000
        BEGIN
            SET @CurrentEnd =  CHARINDEX(CHAR(10), @String) -1
            SET @Offset = 2
        END
        ELSE
        BEGIN
            SET @CurrentEnd = 4000
            SET @Offset = 1
        END   
        PRINT SUBSTRING(@String, 1, @CurrentEnd) 
        SET @String = SUBSTRING(@String, @CurrentEnd + @Offset, LEN(@String))   
    END /*End While loop*/

    ---------------------------------------------------------------------------------
    END TRY
    BEGIN CATCH
        DECLARE @ErrorMessage VARCHAR(4000)
        SELECT @ErrorMessage = ERROR_MESSAGE()    
        RAISERROR(@ErrorMessage,16,1)
    END CATCH
END

вторник, 21 июля 2020 г.

Скрипт размер кубов SSAS

Скрипт выполняется в Power Shell и может быть выполнен с другого сервера.

Param($ServerName="server_name")
$loadInfo = [Reflection.Assembly]::LoadWithPartialName("Microsoft.AnalysisServices")
$server = New-Object Microsoft.AnalysisServices.Server
$server.connect($ServerName)
if ($server.name -eq $null) {
 Write-Output ("Server '{0}' not found" -f $ServerName)
 break
 }
 
$sum=0
foreach ($d in $server.Databases )
 {
 Write-Output ("Database: {0}; Status: {1}; Size: {2}MB" -f $d.Name, $d.State, ($d.EstimatedSize/1024/1024).ToString("#,##0") )
 $sum=$sum+$d.EstimatedSize/1024/1024
 }
 
$SizeGB=$Sum/1024
 
write-host 'Sum of Database = '$sum 'MB'
Write-host 'Total Size of Cube Databases =' $SizeGB  'GB'

пятница, 3 июля 2020 г.

Утилита для просмотра параметров VPN подключений


Dialupass

This utility enumerates all dialup/VPN entries on your computers, and displays their logon details: User Name, Password, and Domain. You can use it to recover a lost password of your Internet connection or VPN.
Dialupass also allows you to save the dialup/VPN list into text/html/csv/xml file, or copy it to the clipboard.