Saturday, January 16, 2010

Configure SQL Server Authentication

In order to use SQL Server authentication you must first configure your server by login with windows authentication.

Right-click on the server node and select 'Properties'.


On the new window select 'Security' from the left menu, select the 'SQL Server and Windows Authentication mode option, click 'OK' to close the dialog.

In the server node expand 'Security' and 'Logins', right click on the login name and select 'Properties'.Under the new window enter a password and confirm the password. Select 'Status' from the left menu, set the 'Login' option to 'Enabled' and click 'OK' to close the dialog.
Now right click on the server node and choose 'Restart' for the changes to take affect and connect with SQL Server Authentication, user 'sa' and you new password.

If you can't connect, you may need restart the service.

Go to Start => All Programs => Micrsoft SQL Server 2005 => Configuration Tools => SQL Server Configuration Manager.

From the left menu, select 'SQL Server 2005 Services', in the right menu right click on 'SQL Server(SQLEXPRESS) and restart it.

Monday, January 11, 2010

Use lambda

Lambda expressions use the lambda operator =>, which is read as "goes to".
(input parameters) => expression
The => operator has the same precedence as assignment (=) and is right-associative.

Example
 int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };
int oddNumbers = numbers.Count(n => n % 2 == 1);

Lamda Expressions are a simpler syntax for anonymous delegates and can be used everywhere an anonymous delegate can be used. However, the opposite is not true;
lambda expressions can be converted to expression trees which allows
for a lot of the magic that LINQ to SQL.

The following is an example using anonymous delegates then lambda expressions.

==Delegate==

delegate(int x)
{
return (x % 2) == 0;
}
==Lambda==
(x => (x % 2) == 0)