Wednesday, August 15, 2012

MSSQL 2008: Database Backup

A couple of days ago it became necessary to set up automatic backups of the database using nothing, but mssql server and t-sql. The backup scenario was simple: make full backup every twenty-four hours at 00:05 and differential backup - every hour. With the following backup file name format: "DatabaseName_yyyy_dd_mm_hh_mm_[full|diff].bak" Daily backups should be stored in a separate folder, with specific name ('yyyy_mm_dd'). So this is how it could be done.

Saturday, June 30, 2012

Regex: conditional regular expression

A few days ago I encountered a small problem in a project that I'm developing: I needed to change the regular expression for a text string so that it did not pass a string consisting of whitespaces.

Wednesday, June 27, 2012

Tip: TODO list in Visual Studio

A quick tip: View -> Task List (CTRL+W, T) brings up a list of all //TODO: comments in the solution.

Monday, April 2, 2012

MVC 3: Partial vs RenderPartial

Both Partial and RenderPartial methods in MVC 3 used for rendering partial views. But what is the difference between those two methods? Since mvc is opensource it is easy to check all the interesting moments right inside the framework code.

Thursday, March 29, 2012

Entity Framework Code First: first glance

I’m currently developing small online store. Usually i use LINQ to SQL to work with database, but this time i decided to use Entity Framework Code First, since i found Code First approach more tidy and comfortable. So this post is about EF Code First and migrations.

Wednesday, February 29, 2012

LINQ: "MSDTC on server is unavailable"

"MSDTC on server 'server name' is unavailable" - sometimes you get this exception while using LINQ to SQL. It means that service called "Distributed Transaction Coordinator" is currently disabled on your server. It is easy to turn it on, but what is wrong with the code, if you get such exception?

Monday, February 27, 2012

Windows: mysterious folders

A few days ago i faced a simple task related with xml parsing. Generally speaking, it was about parsing a bunch of files (around 20 thousand) containing information about domains. This information should be stored into MSSQL database. The situation was the following: those xml files were created under linux os. Each file name matched the following pattern: [domainname].[domainzone].xml and they were sent to me in a .zip archive. So i wrote a simple script, iterating through all .xml files in folder, fetching the data within linq to xml and inserting in in a proper tables. I left this script working and gone to have a coffee.

When i came back i realized, that one single file was missing. The domain name was "aux", and after unzipping the file name appeared to be [_aux_].[_domainzone_].xml_ Something like this - containing underscores. No problem, i decided to rename it and run the script again, but the cursed file refused to be renamed.

I googled this problem and found the answer. The problem is that Windows has some restricted file names, such as for example aux, com, con, prn, nul and others. So it is not possible to create files or folders with such names. I decided to check one more guess: i navigated to this web site and tried to save the web page using my browser. No surprise that I saw a warning.

Thursday, February 16, 2012

Visual Studio: Build vs Rebuild

Visual studio allows to build or to rebuild either solution or single project.

And sometimes i face a common question: what is the difference between those two options?

Both Build and Rebuild commands used for compiling and linking source files. But in case of Build only files, that have been changed since last build will be compiled and linked, the rest will be untouched.

In case of Rebuild ALL the files will be compiled, regardless of whether they have been changed or not since the last build.

The build is definetely faster and could be used if you are sure, that for example the reference files or libraries wasn't changed.

Wednesday, February 15, 2012

LINQ: way to remove duplicate items in the collection

A few days ago I was faced with the need to remove duplicate items from the collection. And I found several ways to solve this problem.