Friday, June 30, 2017

.net typed Datasets: finding out what caused congurency exception

typed datasets have a update command, which has a where clause specifing all original values - easily traced by SQL Server profiler:

'UPDATE [mytable] SET [field1] = @field1, [field2] = @field2
WHERE (([PrimaryKey] = @Original_PrimaryKey) 
AND ((@IsNull_field1 = 1 AND [field1] IS NULL) OR ([field1] = @Original_field1))
AND ((@IsNull_field2 = 1 AND [field2] IS NULL) OR ([field2] = @Original_field2))
'@field1=123, @field2='newStringValue',
@IsNull_field1=0, @Original_field1=1,
@IsNull_fiels2=0, @Original_field2='oldStringValue'

now you can compare the value in the database with the Original_Value from the command and find out which values are differnet - they are blocking.

to do this automatically, you have to catch the exception, get the modified records of the dataset you tried to save, read them again in another dataset and compare those two datasets - (original values)


Wednesday, June 28, 2017

Visual Studio: Custom Tool: Cannot find custom tool ... on this system

try to debug with procmon
filter:
 processname devenv
 path contains your custom tool name


get public key token of assembly

use signtool:
sn -T assemblyname

then use it to reference assambly:
Assembly=assemblyname, Version=1.0.0.0, publicKeyToken=7e3e8edbbbdbe145, Culture=neutral

Visual Studio Custom Tool


https://www.codeproject.com/Tips/1023337/Custom-Tool-Single-File-Generator-for-Visual-Studi

https://www.codeproject.com/search.aspx?q=Custom+Tool&doctypeid=1%3b2%3b3%3b13%3b14

Power Shell Startup Script (profile1, like autoexec.bat)

das autoexec der power shell heißt Microsoft.PowerShell_ profile.ps1 und der PFad dazu ist in $profile gfespeichert.
wenn es noch keines gibt:

# Command to create a PowerShell profile
New-Item -path $profile -type file -force

dann editieren z,.b,:
Set-Location D:\Powershell

http://www.computerperformance.co.uk/powershell/powershell_profile_ps1.htm

Monday, June 26, 2017

path regasm

c:\Windows\Microsoft.NET\Framework\v4.0.30319\RegAsm.exe

Wednesday, June 21, 2017

VisualStudio Before / After Build Commands

Very simple Execute Command BeforeBuild

   



using built in Variables

needs File Resource1.Designer.cs

   



declaring Variables

   
<resfile>"$(ProjectDir)\\Resource1.Designer.cs"


Tuesday, June 20, 2017

ways to change standard resource Manager - T4 Template for (standard) Resource Generator

1) use T4 Template instead of Resource Generator


1) add TextTemplate with same name as your resx file
2) copy and paste
3) edit the template to replace standard resourcemanager with your own

//------------------------------------------------------------------------------
//
//     This code was generated by a tool.
//     Runtime Version:4.0.30319.34003
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
//
//------------------------------------------------------------------------------
<#@ template hostspecific="true" language="C#" #>
<#@ output extension=".Designer.cs" #>
<#@ assembly name="EnvDTE" #>
<#@ assembly name="System.IO" #>
<#@ assembly name="System.Xml" #>
<#@ assembly name="System.Xml.Linq" #>
<#@ import namespace="System.IO" #>
<#@ import namespace="System.Xml.Linq" #>

namespace WpfExp
{
    using System.Globalization;
    using System.Resources;


<#
string resxFileName = this.Host.TemplateFile.Replace(".tt", ".resx");
string className = Path.GetFileNameWithoutExtension(resxFileName);
XDocument doc = XDocument.Load(resxFileName);

#>

///





    ///   A strongly-typed resource class, for looking up localized strings, etc.
    ///
    // This class was auto-generated by the StronglyTypedResourceBuilder
    // class via a tool like ResGen or Visual Studio.
    // To add or remove a member, edit your .ResX file then rerun ResGen
    // with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
    [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
public class <#=className#>
    {

       private static global::System.Resources.ResourceManager resourceMan;
     
        private static global::System.Globalization.CultureInfo resourceCulture;
     
        [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
        public <#=className#>() {}
     
        ///





        ///   Returns the cached ResourceManager instance used by this class.
        ///
        [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
        internal static global::System.Resources.ResourceManager ResourceManager {
            get {
                if (object.ReferenceEquals(resourceMan, null)) {
                    global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("WpfExp.<#=className#>", typeof(<#=className#>).Assembly);
                    resourceMan = temp;
                }
                return resourceMan;
            }
        }
     
        ///





        ///   Overrides the current thread's CurrentUICulture property for all
        ///   resource lookups using this strongly typed resource class.
        ///
        [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
        internal static global::System.Globalization.CultureInfo Culture {
            get {
                return resourceCulture;
            }
            set {
                resourceCulture = value;
            }
        }


<#
if(doc != null && doc.Root != null)
{
foreach(XElement x in doc.Root.Descendants("data"))
    {
        string name = x.Attribute("name").Value;
        WriteLine(string.Empty);
        WriteLine("        public static string " + name);
        WriteLine("        {");
        WriteLine("            get { return ResourceManager.GetString(\"" + name + "\", resourceCulture ?? CultureInfo.CurrentUICulture); }");
        WriteLine("        }");
    }
}
#>

}
}

see also: https://outlawtrail.wordpress.com/2014/03/17/custom-resources-with-t4/

2) change resource.Designer.cs in PreBuild Event:

ProjectProperties , Build Events,  pre build:

powershell.exe -command "(gc ..\..\Resource1.Designer.cs).Replace(\"new global::System.Resources.ResourceManager\", \"new MyResourceManager\") | set-content ..\..\Resource1.Designer.cs -Encoding UTF8"


very simple T4 Example / sehr einfaches T4 Beispiel

1) Add Text Template

Add a new item to your project, choose General/Text Template => TextTemplate1.tt will be added to your project

2) copy and paste below to the tt file:


<#@ template debug="false" hostspecific="false" language="C#" #>
<#@ assembly name="System.Core" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Text" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ output extension=".txt" #>

----------------- BEGINN -----------------------



<#
string name ="mike";
#>

Hello <#= name #> !

<# for (int i=0; i<10 i="" p=""> {
WriteLine("test"+i.ToString());
}
#>

------------------ ENDE ! -------------------


3) look at the results


open child file of texttemplate1.tt, should be TextTemplate1.txt should look like this:
----------------- BEGINN -----------------------




Hello mike !

test0
test1
test2
test3
test4
test5
test6
test7
test8
test9

------------------ ENDE ! -------------------

4) Basic Elements of a tt file:

template language: language in which the tempolate is written
assembly: used to execute
import = using
output= output file extension

every normal Text is simply copied to output (like --- BEGINN ...)

<# // is a code block #>

print variable:

WPF Resource Datei kann nicht aufgelöst werden: Der StaticExtension-Wert Resource kann nicht zu einer Enumeration, einem statischen Feld oder einer statischen Eigenschaft aufgelöst werden.

Der StaticExtension-Wert Resource kann nicht zu einer Enumeration, einem statischen Feld oder einer statischen Eigenschaft aufgelöst werden.

da die Resource Datei defaultmäßig zu einer internal Klasse generiert wird (vom ResXFileCodeGenerator)

Lösung: Properties der Resource Datei, Custum Tool von ResXFileCodeGenerator auf  PublicResXFileCodeGenerator ändern.

Monday, June 19, 2017

SQL SERVER RECOVERY PENDING

cause / Ursache: sql server can't access mdf or ldf file - permissions changed ? enough free space ? / Sql server kann nicht auf das mdf oder ldf file Zugreifen - haben sich die BErechtigungen geändert oder ist zuwenig Speicherplatz frei ?

after file Access is ok / nachdem der Zugriff auf die Files wieder möglich ist:

ALTER DATABASE mydb SET ONLINE;
DBCC CHECKDB('mydb')

or for all pending databases:

select 'DBCC CHECKDB(' + name + ')',* from sys.databases where state=3 -- name like 'mydb%'
select 'ALTER DATABASE ' + name + ' SET ONLINE',* from sys.databases where state=3



Wednesday, June 14, 2017

change sql server hostname

select @@servername -- view servername
EXEC sp_DROPSERVER 'oldservername'
EXEC sp_ADDSERVER 'newservername', 'local'
restart server

important Developer paths / wichtige Entwickler pfade

C:\Program Files\Microsoft SDKs

C:\Program Files (x86)\Microsoft SDKs
C:\Program Files (x86)\Windows Kits

c:\Windows\Microsoft.NET\Framework\v4.0.30319\RegAsm.exe
C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools\gacutil.exe

Thursday, June 01, 2017

linux troubleshooting system analyse

top ... zeigt cpu und memory auslastung
/var/log/ ... log dateien