Skip to main content

Posts

Showing posts from 2017

Encrypting Passwords in c# appSettings

https://weblogs.asp.net/jongalloway/encrypting-passwords-in-a-net-app-config-file This page uses: System.Runtime.InteropServices.Marshal.SecureStringToBSTR System.Runtime.InteropServices.Marshal.PtrToStringBSTR System.Runtime.InteropServices.Marshal.ZeroFreeBSTR System.Security.Cryptography.ProtectedData.Unprotect System.Security.Cryptography.ProtectedData.Protect System.Security.Cryptography.DataProtectionScope.CurrentUser

C# appSettings

You can access key value pairs within appSettings with AppSettingsReader An example is available at  https://docs.microsoft.com/en-us/dotnet/api/system.configuration.appsettingsreader?view=netframework-4.7.1

C# Drive Info

foreach (DriveInfo DI in DriveInfo.GetDrives()) Console.WriteLine( ( DI.IsReady ? (DI.VolumeLabel.Length == 0 ? "Drive Type: " + DI.DriveType.ToString() : "Volume Label: " + DI.VolumeLabel) : "Not Ready : " + DI.DriveType.ToString() ) + // " (" + DI.Name.Replace("\\", "") + ")" " (" + DI.Name + ")" + Environment.NewLine ); Code highlighting compliments of http://markup.su/highlighter/ Another options is  http://hilite.me/

Aliases and selecting from a select

Rarely do you need select from a select statement. Occasionally this pops up with complex PIVOTs and UNPIVOTs. The tip when doing this is (in MSSQL) is the "table" select statement needs to be aliased. For example, the following statement will not work: SELECT * FROM ( SELECT * FROM blah )  However, the following statement will work: SELECT * FROM ( SELECT * FROM blah ) x

Get a list of Field Names and Data Types for a MSSQL table

Use this type of SQL to generate a listing of field names and properties for an MSSQL table USE //Your Database Name// SELECT c .object_id , c .column_id , c .name , types.name , c .[max_length] , c .[ precision ] , c .[ scale ] FROM sys.all_columns c JOIN sys.tables t ON c .object_id = t.object_id JOIN sys.types types ON c .user_type_id = types.user_type_id WHERE t.name = '//Your Table Name//'

SQL table copies - SELECT INTO VS INSERT INTO

Creating a new table from another table  see:  https://www.w3 schools.com/sql/sql_select_into.asp This creates a new table and inserts all the data from the oldtable  SELECT  *  INTO   newtable  FROM   oldtable You can create a new empty table from the schema of an other using a statement like SELECT  *  INTO   newtable  FROM   oldtable  WHERE   1  =  0 ; Copy data from one table into another existing table  see:  https://www.w3schools.com/sql/sql_insert_into_select.asp Insert data from one table into another  INSERT   INTO   table2  SELECT  *  FROM   table1 If you need to specify a column list (as is the cast when dealing with identity insert), the syntax is... The tips are: Brackets are required around the destination fields No brackets are required around the select fields, just like a normal select statement  You need the identity_insert flag SET IDENTITY_INSERT  table2 ON;  INSERT   INTO   table2 ( col1, col2, col3) SELECT

Telstra Mobile Call Forwarding dial codes

To enable voicemail: *61*101**30# Divert to 101 when unanswered after 30 seconds *62*101# Divert to 101 when unreachable *67*101# Divert to 101 when busy *21*101# Divert all calls to 101 To disable voicemail: #61# Cancel divert when unanswered #62# Cancel divert when unreachable #67# Cancel divert when busy #002# Cancel all diverts To Check voicemail diversions: *#61# Check divert when unanswered *#62# Check divert when unreachable *#67# Check divert when busy

Maintaining a Permanent VPN connection

From  http://blog.degree.no/2011/10/permanent-vpn-connection-in-windows/ $ip = "some address or ip" $result = gwmi -query "SELECT * FROM Win32_PingStatus WHERE Address = '$ip'" if ($result.StatusCode -eq 0) { Write-Host "$ip is up." } else{ Write-Host "$ip is down." Write-Host "Disconnecting..." rasdial.exe xxxVPN /DISCONNECT Write-Host "Connecting..." rasdial.exe xxxVPN vpnUsername vpnPassword12345 }