Search This Blog

Tuesday, July 24, 2012

timestamp (Transact-SQL)

SQL Server > Data types > TimeStamp

Timestamp in SQL Server is a data type that exposes automatically generated, unique binary numbers within a database.

  • is generally used as a mechanism for version-stamping table rows. 
  • the storage size is 8 bytes. 
  • the timestamp data type is just an increment number and does not preserve a date or a time. 
  • to record a date or time, use a datetime data type.


Example

IF OBJECT_ID(N'tbl1', N'U') IS NOT NULL
       DROP TABLE tbl1;
GO

CREATE TABLE tbl1
(
       id     int,
       code   timestamp
);
GO

INSERT INTO tbl1(id) values  (1)
SELECT
       *
FROM
       tbl1

Result:

id code
1  0x00000000005C0E69







Friday, July 20, 2012

Update table join SQL Server

SQL Server > Update > Using Join


UPDATE
  tbl1 AS A
  INNER JOIN tbl2 AS B ON A.F1=B.F1
SET

  A.X = 1,
  A.Y = 2
WHERE
  A.id = 100





Wednesday, July 18, 2012

nvarchar data type SQL Server

SQL Server > Data Types > nvarchar


  • variable length 
  • Unicode string data.
  • length can be a value from 1 through 4,000.
  • maximum storage size is 2 GB
Example


CREATE TABLE dbo.Person
(
   Name nvarchar(100)
);








Monday, July 16, 2012

Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack

ASP.NET > Errors

This error normally occurs when we use Response.Redirect or Server.Transfer or Response.End in your code before completing the actual process the page was doing.

In this case what you have to do is

In place of Response.End you have to use HttpContext.Current.ApplicationInstance.CompleteRequest

in place of Response.Redirect, use the Response.Redirect ("home.aspx", false)
in place of Server.Transfer, use the Server.Execute method





Monday, July 9, 2012

DATEADD SQL Server Example

SQL Server > Built-in Functions > DATEADD

Add a number to a specified datepart of that date.

DATEADD (datepart , number , date )

datepart: is the part of date to which an integer number is added.

Example:

SELECT DATEADD(month,1, GetDate()) -- add 1 month to current day
SELECT DATEADD(day,1, GetDate()) -- add 1 month to current day
SELECT DATEADD(year,1, GetDate()) -- -- add 1 year to current day


Find last day of previous month








Monday, June 25, 2012

ref c#

C# Keywords > ref

The ref method parameter keyword on a method parameter causes a method to refer to the same variable that was passed into the method. Any changes made to the parameter in the method will be reflected in that variable when control passes back to the calling method.


using System;
public class MyClass
{
   public static void Ref(ref char x)
   {
      // The value of i will be changed in the calling method
      x = 'a';
   }
   public static void NoRef(char x)
   {
      // The value of i will be unchanged in the calling method
     x = 'b';
   }
   public static void Main()
   {
      char i = '';    // variable must be initialized
      Ref(ref i);  // the arg must be passed as ref
      Console.WriteLine(i);
      NoRef(i);
      Console.WriteLine(i);
   }
}





How to use the Desktop Alerts feature in Outlook


To open the settings dialog box for the Desktop Alerts feature, follow these steps:
  1. On the Tools menu, click Options.
  2. On the Preferences tab, click E-mail Options.
  3. Click Advanced E-Mail Options.
  4. Click Desktop Alert Settings.
In the Desktop Alert Settings dialog box, you can configure the duration and the transparency of your Desktop Alert notifications for when a new e-mail message is received. To turn off the Desktop Alerts feature, click to clear the Display a New Mail Desktop Alert check box.

Note You only receive Desktop Alert notifications if you have Microsoft Exchange server and Post Office Protocol version 3 (POP3) profiles. Internet Mail Access Protocol version 4 (IMAP4) and HTTP accounts do not support the Desktop Alerts feature.









Thursday, June 21, 2012

?? Operator (C# Reference)

C# > Operators > ?? Operator

The ?? operator,also called the null-coalescing operator, returns the left-hand operand if it is not null, or else it returns the right operand.

Example

// y = x, unless x is null, in which case y = 0.
int y = x ?? 0;










Wednesday, June 20, 2012

Parental Controls on Internet Explorer

Parental Controls on Internet Explorer

1. Go to Internet Explorer on your computer. Click on 'Tools' from the toolbar in the upper right-hand corner of the Web browser. Click on 'Internet Options'

2. Select the 'Content' tab.

3. Find the 'Content Advisor' heading and click on the button labeled 'Enable.'

4. Choose a category from the list. This list will present you with a variety of content categories that you may not want your children to see, such as sites depicting drug or alcohol use, violent images, nudity or bad language.

5. Click on the category you want to control. Then use your mouse to move the slider below the list to set the degree of restriction you want on that type of site. the degree of restriction can range from no restriction at all to the complete blocking of those sorts of sites.

6. Click 'OK.'

7. Set a password. You will be prompted to do so at this point. Setting a password will ensure that no one but you is able to adjust the parental control settings.








Tuesday, June 19, 2012

Restart IIS from asp net page

ASP.NET

ServiceController represents a Windows service and allows you to connect to a running or stopped service, manipulate it, or get information about it.
The Internet Information Services (IIS) World Wide Web Publishing Service (W3SVC) manages the HTTP protocol and HTTP performance counters.

Example :
Restart IIS from asp net page

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ServiceProcess;
using System.Threading;

namespace WebApplication1
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            ServiceController sc = new ServiceController("W3SVC");
            if (null != sc)
            {
                if (sc.Status == ServiceControllerStatus.Running)
                {
                    sc.Stop();
                    Thread.Sleep(2000);
                    sc.Start();
                    Response.Write("IIS restarted");
                }
                else
                {
                    Response.Write("IIS started");
                    sc.Start();
                }
            }
        }
    }
}

 





Tuesday, June 12, 2012

ISNUMERIC SQL Server

SQL Server > Built-In Functions > ISNUMERIC

ISNUMERIC returns 1 when the input expression evaluates to a valid numeric data type; otherwise it returns 0

Example:

IF OBJECT_ID(N'tbl1', N'U') IS NOT NULL
       DROP TABLE tbl1;
GO

CREATE TABLE tbl1
(
       id     int ,
       code   varchar(50)
);
GO

INSERT INTO tbl1 values  (1,'aaa'), (2,'b12') , (3,'345')

SELECT
       *
FROM
       tbl1
WHERE
       ISNUMERIC(code) = 1

Result:
 
id code
3  345

 

 






C# Nullable DateTime

C# > System Namespace > DateTime > Nullable DateTime

// Error Cannot convert null to 'System.DateTime' because it is a non-nullable value type 
   
DateTime AgendaValidFrom;
AgendaValidFrom = null;

Solution:
Add ? to DateTime

DateTime? AgendaValidFrom = null; // Declare a nullable DateTime instance and assign to null.





Monday, June 11, 2012

Delete from table using join SQL Server

SQL Server > DML > DELETE

Removes rows from a table.

Example

To delete from tables using join you must specify an alias for the table from which to delete data.

IF OBJECT_ID(N'tbl1', N'U') IS NOT NULL
       DROP TABLE tbl1;
GO
IF OBJECT_ID(N'tbl2', N'U') IS NOT NULL
       DROP TABLE tbl2;
GO

CREATE TABLE tbl1
(
       id           int ,
       name   varchar(50)
);
GO
CREATE TABLE tbl2
(
       id           int ,
       name   varchar(50)
);
GO

INSERT INTO tbl1 values  (1,'john'), (2,'dan') , (3,'laura')
INSERT INTO tbl2 values  (1,'john')
GO

select * from tbl1
--id name
--1 john
--2 dan
--3 laura
DELETE
  a
from
  tbl1 a
join tbl2 b on a.id = b.id

select * from tbl1

--id name
--2 dan
--3 laura



GO






COUNT_BIG SQL Server

SQL Server Built-in Functions COUNT_BIG


COUNT_BIG is the same like COUNT but returns bigint data type value.







Saturday, June 9, 2012

Date Functions C#

C# > System Namespace > DateTime > Add Methods

Returns a new DateTime that adds the specified number of  years, days, minutes, months, seconds to the value of this instance.

Example:

DateTime AgendaValidTill = DateTime.Now.AddYears(10);
// add days
AgendaValidTill = DateTime.Now.AddDays(10);
AgendaValidTill = DateTime.Now.AddMinutes(10);
AgendaValidTill = DateTime.Now.AddMonths(10);
AgendaValidTill = DateTime.Now.AddSeconds(10);








Wednesday, June 6, 2012

Date functions SQL Server

SQL Server > Date&Time > Date Functions



-- Selecting the Current Year/Get Current Year/Separate Year Part from Date
Select DatePart(YY, GetDate()) as Current_Year
-- Selecting the Current Quarter/Get Current Quarter/Separate Quarter Part from Date
Select DatePart(QQ, GetDate()) as Current_Quarter
-- Selecting the Current Month/Get Current Month/Separate Month Part from Date
Select DatePart(MM, GetDate()) as Current_Month
-- Selecting the Current Hour/Get Current Hour/Separate Hour Part from Date
Select DatePart(HH, GetDate()) as Current_Hour
-- Selecting the Current Minute/Get Current Minute/Separate Minute Part from Date
Select DatePart(minute, GetDate()) as Current_Minute

-- Selecting the Name of Current Month/Get Name of Current Month/Separate Month Part from Date and display its Name
Select DateName(month, GetDate()) as Current_Month_Name
-- Selecting the Name of Current Month/Get Name of Current Month/Separate Month Part from Date and display its Name
Select DateName(day, GetDate()) as Current_Day
-- Selecting the Name of Current Month/Get Name of Current Month/Separate Month Part from Date and display its Name
Select DateName(wk, GetDate()) as Current_Week





Restart asp.net application

ASP.NET > HttpRuntime > UnloadAppDomain


HttpRuntime.UnloadAppDomain Method

Terminates the current application. The application restarts the next time a request is received for it.

UnloadAppDomain is useful for servers that have a large number of applications that infrequently receive requests. Rather than keep application resources alive for the lifetime of the process, UnloadAppDomain allows programmatic shutdown of unused applications.

Example

Restart asp.net application


using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace editor.Admin
{
    public partial class restart : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            System.Web.HttpRuntime.UnloadAppDomain();
        }
    }
}

 





Setting up a Sent Mail rule in Thunderbird

Setting up a Sent Mail rule in Thunderbird
1. Click on Tools > Account Settings
2. Under your Account Name (the example below shows Work Account, you may have simply named yours IMAP), select Copies and Folders

Make sure there is a tick next to Place a copy in: You then have TWO choices.
OPTION ONE
"Sent" folder on By default Thunderbird selects "Sent" folder on This means that Thunderbird will create a folder for you called Sent under your IMAP account and all your sent items will filter into this folder.
OPTION TWO
Other You may already have a Sent Mail folder set up on your IMAP account. By selecting Other you can specify which folder you would like your sent mail to filter into. To select an alternative folder: Click on the following icon: Select your Account Name (not Local Folders) Choose the Sent Mail folder you require
Click OK to save your changes.




Friday, February 18, 2011

Extract hour, minute from date column Oracle

Oracle > Extract hour, minute from date column

SELECT
  to_char(column_date,'HH24') hh
  ,to_char(column,'mi') min
from
  table;




Wednesday, February 2, 2011

SQL Server Deadlocks

SQL Server > Deadlocking

Deadlocking occurs when

  •  two user processes have locks on separate objects and each process is trying to acquire a lock on the object that the other process has.

SQL Server identifies the problem and ends the deadlock by: 


  • automatically choosing one process and aborting the other process
  • allowing the other process to continue.

The aborted transaction is rolled back and an error message is sent to the user of the aborted process.
Generally, the transaction that requires the least amount of overhead to rollback is the transaction that is aborted.

Avoid deadlocking on your SQL Server:

  • Ensure the database design is properly normalized.
  • Have the application access server objects in the same order each time.
  • During transactions, don't allow any user input.
  • Avoid cursors.
  • Keep transactions as short as possible.
  • Reduce lock time.
  • If appropriate, reduce lock escalation by using the ROWLOCK or PAGLOCK.
  • Consider using the NOLOCK hint to prevent locking if the data being locked is not modified often.
  • If appropriate, use as low of an isolation level as possible for the user connection running the transaction.