Tuesday, April 11, 2017

How to catch an error and send via email and log to the server (aka simple text file not event log). (VB.NET)

Catch ex As Exception
            'Log to exception table
            Dim strError As String
            strError = Now().ToString() & "Error: (Class=PromoCode;Method=IsEmailRequired)" &
                       ";" & vbCrLf & "PromoId = " & promoCodeId &
                       ";" & vbCrLf & vbCrLf & "Exception " & ex.ToString()


            myPromoCode = Nothing
            Return myPromoCode
        End Try

    'Description: Email Exception Error
    Public Shared Sub SendExceptionEmail(ByVal errorException As String)

        Dim myMail As New MailMessage()

        myMail.From = New MailAddress("error@domain.com")
        myMail.Subject = ConfigurationManager.AppSettings("CoreHTTPPath") & " error exception"

        'Create an email from the email addresses in the app.config file
        Dim emailTo As String = System.Configuration.ConfigurationManager.AppSettings("AdminEmails").ToString()
        Dim strEmailArray() As String

        strEmailArray = Split(emailTo, ";")

        For Each email As String In strEmailArray

        Dim sb As New StringBuilder()
        sb.Append("www.domain.com error exception: " & vbCrLf & vbCrLf)


        Dim strBody As String = sb.ToString()
        myMail.Body = strBody

        myMail.IsBodyHtml = False

        Dim smtp As New SmtpClient()

            myMail = Nothing
        Catch ex As System.Exception
            WriteLogRecord(Now().ToString() & " Error: (Function Sending errorException) " & ex.ToString)
        End Try

    End Sub

    Public Shared Sub WriteLogRecord(ByVal strErroMsg As String)

        Dim objWrite As IO.StreamWriter
        Dim strDateTime As String = Now().ToString()
        strDateTime = Replace(strDateTime, "/", "-")
        strDateTime = Replace(strDateTime, ":", "")
        objWrite = IO.File.AppendText(System.Configuration.ConfigurationManager.AppSettings("EmailErrorLogs") & "/EmailErrorLog.log")

    End Sub

Thursday, February 23, 2017

Count Columns in Table in SQL Server

AND TABLE_NAME = 'TableName'  

Thursday, February 16, 2017

IIS App Pool Recycle Logs

If you need to view information about application pool recycle set a custom view in Windows Event Viewer.

1. Start Search Event Viewer

2. Select Custom Views > Actions: Create Custom View

3. Logged what ever time you need

4. Select all event levels

5. By Source (WAS) Very Important

Click OK.

Thursday, February 02, 2017

SQL Tips


Great new site I found above.

Captain SQL Jason also taught this old dawg some new tricks.  He told me I am not allowed to share them.   They help us Veterans in the field keep our jobs.  :)

Wednesday, November 09, 2016


GOD BLESS AMERICA #MAGA  Congratulations President Elect Donald Trump!

Monday, October 17, 2016

Regular Expressions

To match a string that contains only those characters (or an empty string), try
This works for .NET regular expressions, and probably a lot of other languages as well.
Breaking it down:
^ : start of string
[ : beginning of character group
a-z : any lowercase letter
A-Z : any uppercase letter
0-9 : any digit
_ : underscore
] : end of character group
* : zero or more of the given characters
$ : end of string
If you don't want to allow empty strings, use + instead of *.
EDIT As others have pointed out, some regex languages have a shorthand form for [a-zA-Z0-9_]. In the .NET regex language, you can turn on ECMAScript behavior and use \w as a shorthand (yielding ^\w*$ or ^\w+$). Note that in other languages, and by default in .NET, \w is somewhat broader, and will match other sorts of unicode characters as well (thanks to Jan for pointing this out). So if you're really intending to match only those characters, using the explicit (longer) form is probably best.


Thursday, October 13, 2016

Page size calculation formula

Commit charge:
1. Run Performance Monitor (Perfmon)
2. Go to Data Collector Sets\User Defined
3. Right click on User Defined and select New
4. Select Create Manually and next
4. Check Performance counter
5. Add the following counters:
            Memory\Committed Bytes – Committed Bytes is the amount of committed virtual memory, in bytes.
            Memory\Committed Limit – Amount of virtual memory that can be committed without having to extend the paging file
            Memory\% Committed Bytes In Use – Ratio of Memory\Committed Bytes to the Memory\Commit Limit

Make sure you collect the information over a long period (one week at least), and the server is running at peak usage.

The page file size formula should be:

(Max value of Committed Bytes + additional 20% buffer to accommodate any workload bursts)-RAM size

For example: If the server has 24 GB RAM and the maximum of Committed Bytes is 26 GB, then the recommended page file will be: (26*1.2)-24)  = 7.2 GB