Wednesday, January 31, 2018

Rechner aufräumen / Bereinigen, Performance

Services abdrehen:
Adobe

Deinstallieren:
Bonjour Apple Dienst

Einstellungs App / Persionalisierung / Farben / unten: Transparenz abschalten
Windows Taste + Pause => erweiterte Systemeinstellungen / Erweitert / Visuelle Effekte

Friday, January 26, 2018

sql server FileTable: Create Path

 
DECLARE @Val as nvarchar(4000)
DECLARE @NextVal as nvarchar(4000)
DECLARE @Pathlocator as hierarchyid = NULL
DECLARE @ParentLocator as hierarchyid = NULL
DECLARE @LastChildLocator as hierarchyid =NULL
DECLARE curInserted CURSOR LOCAL FOR  (select * from STRING_SPLIT('a1\b2\c1.txt','\'))
OPEN curInserted
FETCH NEXT FROM curInserted INTO @NextVal
SET @Val=@NextVal
WHILE (@@FETCH_STATUS = 0)
BEGIN
FETCH NEXT FROM curInserted INTO @NextVal

--check if Directory named Val already there (in Dir with parentLocator)
if (@ParentLocator is null)
BEGIN --------- root level => need parent_Path_locator is null
SET @Pathlocator = (select path_locator from MyFile where name like @Val and  parent_Path_locator is null ) -- from main Dir
SET @LastChildLocator = (select top 1 path_locator from MyFile where parent_Path_locator is null order by path_locator desc) -- get latest child
SET @ParentLocator = hierarchyid::GetRoot()
END
ELSE ----- not root level - query with parent_Path_locator = @ParentLocator
BEGIN
SET @Pathlocator = (select path_locator from MyFile where name like @Val and  parent_Path_locator = @ParentLocator ) -- from subdir
SET @LastChildLocator = (select top 1 path_locator from MyFile where parent_Path_locator=@ParentLocator order by path_locator desc) -- get latest child
END

if (@Pathlocator is null) --doesn't exist => have to create
BEGIN
-- get new PathLocator in parent Folder
SET @Pathlocator = @ParentLocator.GetDescendant(@LastChildLocator,NULL)
if (@@FETCH_STATUS = 0) -- not the last entry => its a dir
BEGIN
PRINT 'Create SubDir:' + @Val
INSERT INTO [dbo].MyFile ([name],is_directory,path_locator) SELECT @Val, 1, @Pathlocator  -- insert next child
END
ELSE --last entry =>  file
BEGIN
PRINT 'Create File:' + @Val
INSERT INTO [dbo].MyFile ([name],[file_stream],path_locator) SELECT @Val, CONVERT(VARBINARY(MAX),'TestFileText'), @Pathlocator  -- insert next child
END
END
ELSE
BEGIN
PRINT @Val +' already exists ...'
END
SET @Val=@NextVal
SET @ParentLocator = @Pathlocator
END --WHILE
CLOSE curInserted


select file_stream.GetFileNamespacePath() as RelativePath,  * from MyFile order by creation_time desc
select * from vMyFile where file_stream is null

Thursday, January 25, 2018

sql server: FileTable and hierarchyid, insert folders and files into filetable by tsql

-- Filetablename: MyFile


--create testfolder
INSERT INTO MyFile (name, is_directory)   VALUES ('testFolder', 1)

--insert first file into testfolder:
DECLARE @ParentLocator as hierarchyid = (select path_locator from MyFile where parent_Path_locator is NULL and name like 'testfolder') --get parent
INSERT INTO [dbo].MyFile ([name],[file_stream],path_locator) SELECT 't2.txt', CONVERT(VARBINARY(MAX),'TestFileText'), @ParentLocator.GetDescendant(NULL,NULL) -- insert next child

DECLARE @ParentLocator as hierarchyid = (select path_locator from MyFile where parent_Path_locator is NULL and name like 'testfolder') --get parent

DECLARE @Child1Locator as hierarchyid = (select top 1 path_locator from MyFile where parent_Path_locator=@ParentLocator order by path_locator desc) -- get latest child

INSERT INTO [dbo].MyFile ([name],[file_stream],path_locator) SELECT 't2.txt', CONVERT(VARBINARY(MAX),'TestFileText'), @ParentLocator.GetDescendant(@Child1Locator,NULL) -- insert next child



sql server STRING_SPLIT

--select * from STRING_SPLIT('\dir1\d2\test.txt','\')


 
DECLARE @Val as nvarchar(4000)
DECLARE curInserted CURSOR LOCAL FOR  (select * from STRING_SPLIT('\dir1\d2\test.txt','\'))
OPEN curInserted
FETCH NEXT FROM curInserted INTO @Val
WHILE (@@FETCH_STATUS = 0)
BEGIN
PRINT @Val
  FETCH NEXT FROM curInserted INTO @Val
END
CLOSE curInserted

Wednesday, January 24, 2018

Sql Server Datetime Offset SWITCHOFFSET AT TIME ZONE

--AT TIME ZONE: time and offset are calculated for given timezone
--SWITCHOFFSET: only offset is changed, time remains the same


--create example table _dto for datetimeoffset demo
CREATE TABLE [dbo].[_dto](
[id] [int] IDENTITY(1,1) NOT NULL,
[dtoUtc] [datetimeoffset](7) NULL, --utc time
[dtoLocal] [datetimeoffset](7) NULL --local time
) ON [PRIMARY]
GO

--insert winter and sommertime demo test record
INSERT [dbo].[_dto] ( [dtoUtc]) VALUES (CAST(N'2018-01-23T10:00:00.0000000+00:00' AS DateTimeOffset)) -- winter time
GO
INSERT [dbo].[_dto] ([dtoUtc]) VALUES (CAST(N'2017-07-23T10:00:00.0000000+00:00' AS DateTimeOffset)) -- summer time
GO

--get string values for available sql server time zones:
select * from sys.time_zone_info;

--show result of SWITCHOFFSET and AT TIME ZONE
select dtoUtc ,  --original Utc Time (offset 00)
   SWITCHOFFSET(dtoUtc,1) as switch, -- time remains the same, only offset changes
   dtoUtc AT TIME ZONE 'Central Europe Standard Time' as AtTimeZone -- time and offset are transfered to destination time zone, winter and summer time are calculated correct
from _dto order by dto

--update _dto set dtoLocal= dtoUtc AT TIME ZONE 'Central Europe Standard Time' -- calculating local time from utc and store it
select * from  _dto

--drop table _dto; --clean up

Thursday, January 18, 2018

Tuesday, January 16, 2018

sql server restore full & transactionlog backups

1) check waths inside the backup file:


RESTORE FILELISTONLY from disk = 'L:\My.bak'

you shoul get a list with first column
LogicalName
My 
My_log

RESTORE HEADERONLY FROM DISK='L:\My.trn'
should give you a list of all transaction log backups in this file
next backup FirstLSN=LastLSN of preceeding backup

2) restore full Backup:

use NoRecovery only if you want to restore Transaction Log afterwards

restore database myRestore from disk = 'L:\My.bak' with file=1, NORECOVERY,
move 'My' to 'd:\temp\my2.mdf',
move 'My_Log' to 'd:\temp\my2.ldf'

3) restore Transaction Logs:

restore database myRestore from disk = 'L:\My.trn' with file=1

if there are many transaction log backups in the file my.trn you have to restore it like this:

restore database myRestore from disk = 'L:\My.trn' with file=2

RESTORE HEADERONLY FROM DISK='L:\My.trn'
gives a list of backups in the file

Monday, January 15, 2018

c# iif (boolscherAusdruck) ? trueStatement : falseStatement;

(true) ? 1 : 0; //liefert immer 0 string todoStr = (done) ? "done !" : "todo";

Friday, January 12, 2018

local system, local service and so on / lokaler Dienst lokales System usw.

Following are NOT advised as it grant more privileges than required for running SQL Server Services Local System is a very high-privileged built-in account. It has extensive privileges on the local system and acts as the computer on the network. The actual name of the account is "NT AUTHORITY\SYSTEM". The Local Service account is a built-in account that has the same level of access to resources and objects as members of the Users group. This limited access helps safeguard the system if individual services or processes are compromised. Services that run as the Local Service account access network resources as a null session without credentials. Be aware that the Local Service account is not supported for the SQL Server or SQL Server Agent services. The actual name of the account is "NT AUTHORITY\LOCAL SERVICE". The Network Service account is a built-in account that has more access to resources and objects than members of the Users group. Services that run as the Network Service account access network resources by using the credentials of the computer account. The actual name of the account is "NT AUTHORITY\NETWORK SERVICE"

Wednesday, December 06, 2017

bin und obj rekursiv löschen / Delete bin and obj recursive

Get-ChildItem .\ -include bin,obj -Recurse | foreach ($_) { remove-item $_.fullname -Force -Recurse }

Get-ChildItem .\ -include bin,obj -Recurse | foreach ($_) { remove-item $_.fullname -Force -Recurse }

Thursday, October 12, 2017

WPF Extrem Simple Viewmodel Binding

namespace WpfExp
{
    public class ViewModel
    {
        public string ViewModelText => "MyViewModelText";
    }
}

XAML:

im Window Tag: WICHTIG nicht DataContect Direkt im Window Tag angeben, sondern extra wie folgt:
<Window.DataContext><local:ViewModel></local:ViewModel></Window.DataContext>

dann nutzen:

<Button Content="{Binding ViewModelText}" Background="Chartreuse" />




Tuesday, October 03, 2017

collapse Regions in visual studio VS 2017

Extras / Optionen / Text Editor / C# / Erweitert
#regions beim Reduzieren auf Definitionen ausblenden


Thursday, September 21, 2017

asp.net

speichern von Infos, die über page lifetime hinausgehen:
session: wenn sie abläuft sind die daten weg
application: wenn recycled weg
viewstate: wird auf client seite gespeichert

hard links windows

https://www.howtogeek.com/howto/16226/complete-guide-to-symbolic-links-symlinks-on-windows-or-linux/

Windows 10 auf Hyper V installieren: Genration 2 wählen

Bei Generation 1 kommt:
"Die Microsoft-Software-Lizenzbedingungen wurden nicht gefunden. Stellen Sie sicher, dass die Installationsquellen gültig sind, und starten Sie die Installation erneut."

Bei durch VM mit Generation 2 funktioniert alles perfekt

Wednesday, September 20, 2017

make W10 Install ISO / Stick: https://www.microsoft.com/de-de/software-download/windows10

https://www.microsoft.com/de-de/software-download/windows10

sql Server Commandline Installation

Sql Express Setup from Command Prompt

only required parameters:

only sql server (db)

SETUP.EXE /QUIETSIMPLE /ACTION=Install /FEATURES=SQL /INSTANCENAME=SQLEXPRESS /SQLSVCACCOUNT="NT Authority\System" /SQLSYSADMINACCOUNTS="sqlpc\admin" /AGTSVCACCOUNT="NT Authority\System" /SECURITYMODE=SQL /sapwd="abc!" /IAcceptSQLServerLicenseTerms

with reporting services

SETUP.EXE /QUIETSIMPLE /ACTION=Install /FEATURES=SQL,RS /INSTANCENAME=SQLEXPRESS /SQLSVCACCOUNT="NT Authority\System" /SQLSYSADMINACCOUNTS="sqlPc\admin" /AGTSVCACCOUNT="NT Authority\System" /SECURITYMODE=SQL /sapwd="abc!" /IAcceptSQLServerLicenseTerms

with Directories specified


.\SETUP.EXE /QUIETSIMPLE /ACTION=Install /FEATURES=SQL /INSTANCENAME=SQLEXPRESS /SQLSVCACCOUNT="NT Authority\System" /SQLSYSADMINACCOUNTS="sqlPc\admin" /AGTSVCACCOUNT="NT Authority\System" /SECURITYMODE=SQL /sapwd="abc!" /SQLTEMPDBDIR="C:\sqlData\\" /SQLUSERDBDIR="C:\sqlData\\" /SQLUSERDBLOGDIR="C:\sqlData" /IAcceptSQLServerLicenseTerms


Monday, September 18, 2017

c# LINQ Schreibweise

//SQL Like
var ret1 = from sb in colShiftbooks select new {sb.Id};

//function
var ret2 = colShiftbooks.Select(sb => new {sb.Id});

Wednesday, September 13, 2017

c# Task Error Handling

                mail.SendAsync().ContinueWith(antecedent =>
                                              {
                                                  if (antecedent.IsFaulted)
                                                  {
                                                      _logger.Warn(antecedent.Exception, "Failed sending email");
                                                  }
                                                  else if (antecedent.IsCanceled)
                                                  {
                                                  }
                                                  else
                                                  {
                                                      _logger.Info("Succeed send email");
                                                  }
                                              });