Tuesday, July 15, 2014

SQL SERVER – How to Allow Only Alphabets in Column – Create Check Constraint to Insert Only Alphabets


user can create a check constraint over column to allow insertion of alphabets in the column. Here is a sample script where I demonstrate how users can create constraint over column first so it only allows alphabets.

USE tempdb
GO
-- Create Test tableCREATE TABLE TestTable(ID INT, FirstCol VARCHAR(100),CONSTRAINT FirstCol CHECK (FirstCol NOT LIKE '%[^A-Z]%'))GO-- This will be successfulINSERT INTO TestTable (ID, FirstCol)VALUES (1, 'SQLAuthority')GO-- This will throw an errorINSERT INTO TestTable (ID, FirstCol)VALUES (1, 'SQLAuthority 1')GO-- Clean upDROP TABLE TestTable
GO

Monday, July 14, 2014

get the Computer's Unique ID asp.net

string cpuInfo = string.Empty;
ManagementClass mc = new ManagementClass("win32_processor");
ManagementObjectCollection moc = mc.GetInstances();

foreach (ManagementObject mo in moc)
{
     if (cpuInfo == "")
     {
          //Get only the first CPU's ID
          cpuInfo = mo.Properties["processorID"].Value.ToString();
          break;
     }
}
return cpuInfo;

Tuesday, July 8, 2014

Problem using context in global.asax file asp.net iis7

 <%@ Application CodeBehind="Global.asax.cs" Language="C#" %>

<script RunAt="server">
    public void Application_Start()
    {
        string str = Context.Request.Url.AbsoluteUri.Replace("http", "https");
        Context.RewritePath(str);
    }
</script>
Error will like this:
"Request is not available in this context"
 Now Just modify code like bellow in Global.asax
 
The main reason is that the RewritePath is not working because the http and https are working on different port. Also the Application Start is not the place to call this thinks. The BeginRequest is the one. 
protected void Application_BeginRequest(Object sender, EventArgs e)
{
    HttpApplication app = (HttpApplication)sender;
    string cTheFile = HttpContext.Current.Request.Path;
    string sExtentionOfThisFile = System.IO.Path.GetExtension(cTheFile);
    if (sExtentionOfThisFile.Equals(".aspx", StringComparison.InvariantCultureIgnoreCase))
    {
        if (!app.Context.Request.IsSecureConnection)
        {
            Response.Redirect(app.Context.Request.RawUrl.Replace("http://", "https://"), true);
            return;
        }
    }

    // rest of your code here and below
} 
 
it's working 100%.. 
 

Opps Part 1 : Abstraction

  Abstraction in C# is a fundamental concept of object-oriented programming (OOP) that allows developers t...