How to Enable/Configure sa User in SQL Server 2005

First of all, SQL Server Log In is to be enabled.
# Right click on sa or other user you want to enable and click on Properties.

# In the left Pane select General, change and confirm Password in Right Pane for User if it requires.

# Select Status in Left Pane and check Enable under Login in Right Pane.

# Press OK and restart the SQL Server.

Thanks
A Rahim Khan

Tackling Apostrophes in SQL String with C#

Apostrophes always screws up SQL string that contains inputs from user. The easiest way to deal with this is to checkout each string input from user and replace single apostrophes with two apostrophes.

Utility.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ApostrphesTrial
{
public static class Utility
{
public static string EscapeApostrophes(string input)
{
return input.Replace("'", "''");
}
}
}

Use this “EscapeApostrophes” Method each time with user input (string) to create a SQL string for database interaction.

string userName = Utility.EscapeApostrophes(userNameTextBox.Text);

Thanks
A Rahim Khan

How to write Trigger in SQL Server 2005

A trigger is a special kind of stored procedure that responds to specific events. More specifically, it is attached to a Table or View or Database schemas for tracking the operations on them. The key difference between a trigger and a stored procedure is that the former is attached to a table or view and is fired only when an INSERT, UPDATE, and/or DELETE occurs, whereas a stored procedure executes at any time when it is called.

//Create Table
create table t_EmployeeInformation
(
employee_ID int identity(1,1) NOT NULL,
employee_Name varchar(50),
employee_EmailID varchar(20),
employee_Status varchar(10) NULL constraint
DF_t_EmployeeInformation_employee_Status default ('Active')
)

//Create Procedure
create procedure p_InsertEmployee
@employee_Name varchar(50),
@employee_EmailID varchar(40),
as
begin
insert into t_EmployeeInformation(employee_Name,employee_EmailID)
values(@employee_Name,@employee_EmailID)
end

The following code snippet shows a simple trigger which fires on an insert to table t_EmployeeInformation.

//Create Trigger
create trigger tr_InsertEmployee
on t_EmployeeInformation
after insert
as
begin
declare @employee_ID int
select @employee_ID = employee_ID from inserted
update t_EmployeeInformation
set employee_Status = 'Inactive'
where employee_ID != @employee_ID
end

//Use Procedure to Insert Data
exec p_InsertEmployee 'khan', 'khan.rahim@gmail.com'

Trigger will fire for the insert event and change all available employee_Status except the last (inserted) one.

Thanks
A Rahim Khan

How to write Function in SQL Server 2005

User Defined Functions in SQL Server stops coders write redundant code. There are two types of UDFs:
❑ Those that return a scalar value
❑ Those that return a table

//Create Table
create table t_EmployeeInformation
(
employee_ID int identity(1,1) NOT NULL,
employee_Name varchar(50),
employee_EmailID varchar(20)
)

Following code snippet shows a function that returns a scalar value.

//Create Function
create function f_GetEmployeeId(@employee_EmailID varchar(50))
returns int
as
return
(
select employee_ID from t_EmployeeInformation
where employee_EmailID = @employee_EmailID
)

//Use Function
select dbo.f_GetEmployeeId('khan.rahim@gmail.com')

This creates a function that returns a table.

//Create Function
create function f_GetEmployee(@employee_EmailID varchar(50))
returns table
as
return
(
select employee_ID as "ID", employee_Name as "Name"
from t_EmployeeInformation
where employee_EmailID = @employee_EmailID
)

//Use Function
select * from dbo.f_GetEmployee('khan.rahim@gmail.com')

Thanks
A Rahim Khan

How to Write Stored Procedure in SQL Server 2005

I always prefer writing stored procedure over writing query to insert data in table. If you have an auto-increment field in table as key, you will require this key value of last inserted data for various purposes. Writing stored procedure is the simplest way to address this scenario.

//Create Table
create table t_EmployeeInformation
(
employee_ID int identity(1,1) NOT NULL,
employee_Name varchar(50),
employee_EmailID varchar(20)
)

//Create Procedure
create procedure p_InsertEmployee
@employee_Name varchar(50),
@employee_EmailID varchar(40),
@employee_ID int output
as
begin
insert into t_EmployeeInformation(employee_Name,employee_EmailID)
values(@employee_Name,@employee_EmailID)
set @employee_ID = SCOPE_IDENTITY()
end

//Use Procedure to Insert Data
declare @employee_ID int
exec p_InsertEmployee
'khan', 'khan.rahim@gmail.com',@employee_ID out
select @employee_ID

Thanks
A Rahim Khan

Magento Installation Error (Errcode: 13)

Error in file: “C:\docroot\magento\app\code\core\Mage\Sales\sql\sales_setup\mysql4-install-0.9.0.php” – SQLSTATE[HY000]: General error: 1 Can’t create/write to file ‘C:\WINDOWS\TEMP\#sql_2e8_0.MYI’ (Errcode: 13)

The mentioned error is the most  frustrating one  while trying Magento Installation on local host particularly in Windows XP environment.

Here is the solution, you obviously have some anti virus running on your computer/Laptop, just disable it while installing magento, you will have your problem solved.

Thanks
A Rahim Khan