Sunday, January 22, 2012

Schedule Daily backup of database in MS-SQL Server 2008

1. Open Management Studio.
2. Under "Mangement"  select Maintenance Plans.
3. Right click  and choose New Plan (it will ask for name).
4. Double click on Subplan_1 and change it to your name.
5. Drag from toolbox "Back Up Database Task" control.
6. Right click on it and choose Edit.
7. Choose Backup Type, Databases  and change more fields.
8.OK
9. Click on Job Schedule (in end of row) and set backup date/time.
10. Save plan.
11. Under "Mangement" right click on your job and choose "Execute" for validation.


Enjoy!






Tuesday, November 08, 2011

Installing and Running IIS and Apache Server Together

We working on project that include web application based on python and several application based on IIS (as WCF , Web application, web site ant etc'). "Python" application use port 80 therefore we cannot use same port in IIS application. HERE was explained solution that based on 2 IP addresses.

p.s. One more note: you must run command prompt as administrator.

Tuesday, September 06, 2011

"The specified metadata path is not valid." error in using Windows Service and Entity Framework

I have project (Windows Service) that use Entity Framework model as external DLL.
I cannot use a metadada as embedded resource and must define connection string in config file of Windows Service. In the Debug mode I got right result, I created setup project and installed service in directory but a immediately I saw the next error:

 The specified metadata path is not valid. A valid path must be either an existing directory, an existing file with extension '.csdl', '.ssdl', or '.msl', or a URI that identifies an embedded resource.
I'll not tell you what I not tried  and a solution was found after deep research in order to understand where is run Windows Service. Bad news! Windows Service not run in installed directory therefore all path's to files in config file must be define as physical path otherwise application cannot find it. Windows service use relative path different to installation directory.

Where you use Entity Framework you must to define row as this one:
...metadata=.\ServiceModel.csdl|.\ServiceModel.ssdl|.\ServiceModel.msl...
In order to not change path to physical path just add next row in event OnStart in Windows Service:
System.IO.Directory.SetCurrentDirectory(System.AppDomain.CurrentDomain.BaseDirectory);

This is a way to define relative path of Service as installed directory.

Enjoy!

kick it on DotNetKicks.com

Tuesday, August 23, 2011

Trim leading zeros

REPLACE(LTRIM(REPLACE([Column], '0', ' ')), ' ', '0')
Thanks, 

Friday, August 05, 2011

Paging in LINQ

Implementation of paging  with help from ROW_COUNT() of SQL in LINQ :

Implementation:

public static IEnumerable<T> Paging<T>(int rowCount, int pageId, IQueryable<T> query)

{

    return  query       

        .Skip((pageId - 1) * rowCount)

        .Take(rowCount);

}

Using:

private void TestMethod()

{

    Random rnd = new Random();

    List<Foo> fooList = new List<Foo>();

    for (int i = 0; i < 20; i++)

    {

        fooList.Add(

                new Foo

                {

                    ID = rnd.Next(100),

                    Name = Membership.GeneratePassword(5, 0)

                }

            );

    }

 

    var query = fooList.OrderBy(item => item.ID).AsQueryable();

 

   Console.WriteLine("Attempt 1");

   Paging(10, 1,query )

       .ToList()

       .ForEach(

        item => Console.WriteLine(item.ID + ": " + item.Name)

        );

    Console.WriteLine("Attempt 2");

    Paging(5, 2, query)

        .ToList()

        .ForEach(

        item => Console.WriteLine(item.ID + ": " + item.Name)

        );

}

Class:

public class Foo

{

    public int ID { get; set; }

    public string Name { get; set; }

}

 


And now as extension!

Enjoy!

kick it on DotNetKicks.com