Gilad Lavian's Blog

In Development
דרוש מהנדס\ת פיתוח תשתיות לעבודה בכרמיאל

מהנדס/ת פיתוח בקבוצת תשתיות

  • תואר MCSD או דומה
  • תואר ראשון בהנדסת תוכנה/מערכות מידע מדעי המחשב
  • נסיון בפיתוח בסביבת NET C#, ASP.Net
  • הכרה וניסיון של טכנולוגיות WEB, XML, XSL, DHTML, Java Script
  • דגש על ניסיון בפיתוח User Interface בטכנולוגיות חדשות או
    ניסיון בתשתיות, Multi Threading, Server
  • יכולת עבודה עצמאית ונכונות לעמוד בתנאי לחץ אנגלית ברמה טובה


הערות:
היקף משרה - משרה מלאה
מיקום – כרמיאל
נדרשים מועמדים עם ניסיון של שנתיים ומעלה (לא בוגרים!)
עדיפות למועמדים תושבי האזור והסביבה הקרובה (מהקריות צפונה).



קו”ח יש לשלוח אל: gilad.lavian@gmail.com



MS-SQL: Changing single user Database to multi users

The problem:

Changes to the state or options of database "DatabaseName" cannot be made at this time. The database is in single-user mode, and a user is currently connected to it.

 

The solutions:

use master
go

alter database "DatabaseName" set multi_user;

 

If there's users connected to the Database and you don't know who, you can use "sp_who2" to check who's connected.

 

You can kill only user process by there SPID:

kill 15;

First Impression: Oracle g11 Developer Tools

oralogo_small The g11 release of Oracle Developers Tools (ODT) includes powerful features integrated with Visual Studio.

I must say that this is a major change, the features included in this version makes the common developing and database maintenance much easier.

 

Its supports:

  • Visual Studio 2008/2005/2003
  • Oracle database version 9.2 and later


Enhanced integration with Visual Studio 2008 and Visual Studio 2005

 

Integrated

 


An Oracle Database Project to provide source control of Oracle SQL scripts

 

 SourceControl

 

Integration with Microsoft Query Designer

 

QueryDesigner

 

Read more...

Generic EventArgs<T>

A good way for passing data with EventArgs

public class EventArgs<TValue1> : EventArgs
{
    public TValue1 Value1 { get; set; }
    public EventArgs(TValue1 value1)
    {
        Value1 = value1;
    }
}

Should you want to pass 2 values

public class EventArgs<TValue1, TValue2> : EventArgs<TValue1>
{
    public TValue2 Value2 { get; set; }
    public EventArgs(TValue1 value1, TValue2 value2)
        : base(value1)
    {
        Value2 = value2;
    }
}

The same goes to CancelEventArgs

public class CancelEventArgs<TValue1> : CancelEventArgs
{
    public TValue1 Value1 { get; set; }
    public CancelEventArgs(TValue1 value1)
    {
        Value1 = value1;
    }
}
Extension Methods: IDataReader.GetValue<T>

A convenient solution to get value from IDataReader field.

/// <summary>
/// Gets the reader field value.
/// </summary>
/// <typeparam name="TField">The type of the field.</typeparam>
/// <param name="reader">The reader.</param>
/// <param name="fieldName">Name of the field.</param>
/// <returns></returns>
public static TField GetValue<TField>(this IDataReader reader, string fieldName)
{
    //Guard
    if (string.IsNullOrEmpty(fieldName)) throw new ArgumentException("fieldName");
    return (TField)reader.GetValue(reader.GetOrdinal(fieldName));
}

Usage:

IDataReader reeader = _database.ExecuteReader(command);
if (reader.Read())
{
    int productId = reader.GetValue<int>("ProductId");
}
Start Detached AddIn

StartNewInstanceDetachedThis Addin add new option to the debug menu for each project (When right clicking from Solution  Explorer).

 

Features

  • Starts a new instance for the selected project.
  • In case the project is not executable, a dialog is popped asking the user what to do.

 

Requirements

  • Microsoft .NET Framework 2.0
  • Visual Studio 2008

 

 

For more information click here.

 

Download Version 1.0.0

Build Error on empty lines in Post-build event command line

The following error message raised when trying to compile a Project with an empty line on the Post-build event command line:

ErrorOnEmptyLine

 

The empty line in the Post-build event command line:

ErrorOnEmptyLine2 

 

Resolving this problem is simply to delete the empty line in the Post-build event command line.

SmartClient: Changing the Projects File System Structure

When creating a new smart client project by GAT (Guidance Automation Toolkit) the projects structure hierarchy on the file system is also created by the GAT.

Suppose I move the projects to another location on the file system and to and include this projects in different solution, then, I try to add a new BusinessModule, I will get the following exception:

 

Microsoft.Practices.RecipeFramework.ValueProviderException: An exception occurred during the binding of reference or execution of recipe CreateBusinessModuleCS. Error was: An error happened while calling the value provider or evaluating the default value of argument ShellProject.

 

The SmartClient searches for the root ShellProject in the solution, but since I moved the SmartClient projects to another solution in a different folder on the file system, it couldn't find it.

 

To resolve this situation, take the following steps:

  1. Go to the solution.sln file created by the GAT.
  2. In the solution.sln file, find this line: GlobalSection(ExtensibilityGlobals) = postSolution and copy the entire block.
  3. Paste the copied clock to the current solution.sln where you just moved your SmartClient projects (Infrastructure.Interface, Infrastructure.Library, Shell...).

The entire block should look like this:

 

GlobalSection(ExtensibilityGlobals) = postSolution
        RootNamespace = YourSmartClientSoulitionName
        CommonProjectGuid = f8120216-d992-4073-98b1-1fb43a16e73d
        ShellProjectGuid = cc5c6234-2ae4-4819-be7d-044e89968528
EndGlobalSection

 

Close and reopen the solution, try to add new BusinessModule.

OWASP Israel 2008 Conference
owasp_logo

" The OWASP Israel 2008 conference will be help on September 14th at the Interdisciplinary Center Herzliya. This time we are raising the bar and will be holding a full day two tracks event. The tracks would be split according by level: a beginners track and an experts track. "

 

If you are a security expert or just interest in learning security issues, this is the place!

 

https://www.owasp.org/index.php/OWASP_Israel_2008_Conference

Pinpoint Impersonate

In common web developing, I use impersonation to identify against some services, and some other applications like SQL server with my windows credentials.

 

The usual way is to add to the web.config this line: <identity impersonate="true"/>

This is best practice for most cases in web developing, but the problem here is, it will effect on all identification procedures we have in the application.

 

Pinpoint Impersonation

Suppose I don't want it to effect all my identification procedures, and I want to impersonate just for the specific procedure in my code and then undo the impersonation action, here is a nice way for pinpoint impersonation:

public static void Impersonate()
{
    IPrincipal principal = HttpContext.Current.User; 
    WindowsIdentity identity = (WindowsIdentity)principal.Identity; 
    identity.Impersonate(); 
    string userName = identity.Name;
}

public static void UndoImpersonate()
{
    IPrincipal principal = HttpContext.Current.User;
    WindowsIdentity identity = (WindowsIdentity)principal.Identity;
    identity.Impersonate().Undo();
    string userName = identity.Name;
}
Code Snippet RW (Response.Write)

Code Snippet For Response.Write

 

Ok, this code snippet must be the oldest trick in the book, but still I think it will help to developers how doesn't know about it.

 

1. Create a file name rw.snippet

2. Copy this XML code and save it.

3. From the tools menu in VS, select "Code Snippets manager".

4. Select import, and point it to the saved file.

5. To use the snippet write rw in the code editor.

6. Enjoy!

 

<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets  xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
    <CodeSnippet Format="1.0.0">
        <Header>
            <Title>rw</Title>
            <Shortcut>rw</Shortcut>
            <Description>Code snippet for Response.Write</Description>
            <Author>Gilad Lavian</Author>
            <SnippetTypes>
                <SnippetType>Expansion</SnippetType>
            </SnippetTypes>
        </Header>
        <Snippet>
            <Code Language="csharp"><![CDATA[Response.Write($end$);]]>
            </Code>
        </Snippet>
    </CodeSnippet>
</CodeSnippets>

Parsing DateTime formats

A few ways to handle dates in application:

try
{
    //Tells the parser to expect a he-IL (culture) date format
    DateTime dateParse = DateTime.Parse("28/02/2008", new CultureInfo("he-IL"));

    //Tells the parser to expect a date with specific date format
    DateTime dateParseExact = DateTime.ParseExact("28/02/2008", "dd/MM/yyyy", null);

    //Tells the parser to expect a date with specific date format 
    //with exact hours, minutes and seconds
    DateTime dateTimeParseExact = 
        DateTime.ParseExact("28/02/2008 23:29:02", "dd/MM/yyyy HH:mm:ss", null);

    Console.WriteLine(string.Format("{0} = {1}", "dateParse", dateParse));
    Console.WriteLine(string.Format("{0} = {1}", "dateParseExact", dateParseExact));
    Console.WriteLine(string.Format("{0} = {1}", "dateTimeParseExact", dateTimeParseExact));
}
catch (FormatException ex)
{
    Console.WriteLine(ex.ToString());
}
IIS Errors on Windows XP: Failed to access IIS metabase, and Mutex could not be created

 powered-by-iis6-1of2powered-by-iis7-1of2

Failed to access IIS metabase

System.Web.Hosting.HostingEnvironmentException: Failed to access IIS metabase

I solved this by Reinstalling the .NET 2.0 Framework via aspnet_regiis -i

 

Mutex could not be created

System.InvalidOperationException: Mutex could not be created

The Solution for this error is bit more complicate:

  1. Close all opened Visual Studios.
  2. Navigate to C:\Windows\Microsoft.NET\Framework\v2[....]\Temporary ASPNET pages.
  3. Delete the folder for your application (You can delete the temporary folder completley)
  4. Perform IISReset via command line or via inetmgr.exe
  5. Browse your application directly from IIS and not from any where else.
  6. You should see your application correctly now.

Good Luck !

LINQ To SQL - Executing Text Queries

Executing text queries with LINQ is simple as that...

 

Assuming you have Adventure Works Database installed.

public void DoExecuteQuery()
{
    AdventureWorksDataContext aw = new AdventureWorksDataContext();

    IEnumerable<Employee> employees = 
        aw.ExecuteQuery<Employee>("SELECT * FROM HumanResources.Employee");

    foreach (Employee e in employees)
    {
        Console.WriteLine(e.Title);
    }
}
LINQ To SQL - Performing Inner Join Queries

Its amazing how simple it is to create inner join queries with LINQ.

 

Assuming you have the AdventureWorks Database installed.

 

public void GetEmployeeByID(int employeeID) { AdventureWorksDataContext aw = new AdventureWorksDataContext(); aw.Log = Console.Out; var entities = from e in aw.Employees join ea in aw.EmployeeAddresses on e.EmployeeID equals ea.EmployeeID join a in aw.Addresses on ea.AddressID equals a.AddressID join c in aw.Contacts on e.ContactID equals c.ContactID where e.EmployeeID == employeeID select new { Title = e.Title, FirstName = c.FirstName, LastName = c.LastName, City = a.City, AddressID = ea.AddressID }; foreach (var e in entities) { Console.WriteLine("Title = {0}, FirstName = {1}, LastName = {2}",

e.Title, e.FirstName, e.LastName); } }

 

The text query and the results:

LINQ Inner Joins

More Posts Next page »