Search This Blog

Thursday, January 24, 2013

Regular expression pattern Split method in C#

C# > Text > Regular Expressions > Split

Splits an input string into an array of substrings at the positions defined by a regular expression pattern.

Example:
string path = "some_text_words";
string[] substrings = Regex.Split(path, "_");
foreach (string match in substrings)
{}






Wednesday, January 23, 2013

Database Mail Views (SQL Server)

SQL Server > Catalog Views > Database Mail

These views are located in the msdb database.

Database Mail has views for displaying Database Mail e-mails information such as status of e-mails, any messages received and errors logged by Database Mail.

sysmail_allitems

Contains one row for each message processed by Database Mail.

Important columns


Name
Description
mailitem_id
Identifier of the mail item in the mail queue.
profile_id
The identifier of the profile used to send the message.
recipients
The e-mail addresses of the message recipients.
subject
The subject line of the message.
body
The body of the message.
sent_status
The status of the mail. Possible values are:
  • sent - The mail was sent.
  • unsent - Database mail is still attempting to send the message.
  • retrying - Database Mail failed to send the message but is attempting to send it again.
  • failed - Database mail was unable to send the message.
sent_date
The date and time that the message was sent.

sysmail_faileditems

Contains information about  messages were not successfully sent.
Has the same colums as but sent_status value is always failed.
To view the reason for the failure see onformation in the sysmail_event_log view.

sysmail_event_log

Contains one row for each message returned by the Database Mail system.
When troubleshooting Database Mail, search in sysmail_event_log view for events related to e-mail failures.

Important columns:


event_type
Errors, warnings, informational messages, success messages
log_date
The date and time the log entry is made.
description
The text of the message being recorded.
mailitem_id
Identifier of the mail item in the mail queue.

 




Set hour and minute to a date SQL Server


SQL Server > Datetime > Set hour and minute to a date

declare @d1 datetime

set @d1 = (Select DateAdd(hour, 6, cast(floor(cast(getdate() as float))as datetime)))
set @d1 = (Select DateAdd(minute, 45, @d1))

print @d1
Result:
Jan 23 2013 6:45AM







Full screen application (C#)

TopMost
Gets or sets a value indicating whether the form should be displayed as a topmost form.






private void Form1_Load(object sender, EventArgs e)
{
  this.MaximizeBox = false;
  this.MinimizeBox = false;
  this.TopMost = true;
  this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
  this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
}

Tuesday, January 22, 2013

Stop Statement (VB.NET)

VB.Net > StatementsStop

Stop is a programmatic alternative to setting a breakpoint and suspends the execution. When the debugger finds Stop statement, it breaks execution of the program.

Note: Unlike End, it does not close any files or clear any variables.

Example:

Dim i As Integer
Dim j As Integer
For i = 1 To 100
 j = i + 1
 Stop
Next i







With...End With Statement (VB.NET)

VB.NET > Statements > With...End With

Executes a series of statements that repeatedly refers to a single object or structure.

By using With...End With, you can perform a series of statements on a specified object without specifying the name of the object multiple times.

Example:


Public Class Form1
  Private Class Customer
    Public Property Id As String
    Public Property Name As String
  End Class
  Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    With New Customer
      .Id = 1
      .Name = "Elsoft"
      MessageBox.Show(.Name)
    End With
  End Sub




Monday, January 21, 2013

Temporary Tables (SQL Server)

SQL Server > Temporary tables

Local temporary tables
  • visible only to their creators during the same connection to an instance of SQL Server
  • deleted after the user disconnects from the instance of SQL Server
  • local temporary table name is stared with hash ("#") sign.
Example

Create temporary table

    Global temporary tables

    • visible to any user and any connection after they are created
    • deleted when all users that are referencing the table disconnect from the instance of SQL Server
    • global Temporary tables name starts with a double hash ("##")