Thursday, July 30, 2009

LINQ to SQL samples in C#

Apparently you can easily find LINQ 2 SQL samples in VB.NET but you won't find it searching on MSDN for c#. Way 2 Go MSFT.

string concatenation ( "+=" ) vs StringBuilder in c#

According to the ASP.NET MVC product team, in small sets of concatenation operations, it's faster to use string concatenation i.e. "+=" syntax as opposed to instantiating a StringBuilder. I personally find using "+=" to be more readable than extra lines of new StringBuilder()...stringBuilder.Append(...) and so forth.
The examples from the team's book use the += concatenation approach.

Wednesday, July 29, 2009

Prevented from saving changes when changing database schema in SQL Server 2008




Although this option is automatically enabled by default for probably good reason, if this option is getting in your way, then you can disable it. It's simple:

  1. in management studio, go to Tools -> Options


  2. Then in Designers, uncheck the option "Prevent saving changes..."

.sql script to export, transfer or copy SQL Server 2008 database




A common task for developers is to copy a database, with its schema, with or without its data, over to a new database. For example, if you own a small website and have a shared hosting provider, you'll want to get your database from your machine to their server.
Oftentimes there are many solutions to a problem and we want the simplest here. SQL Server 2008 has a surprisingly simple solution if it's not immediately obvious at first.

  1. open up SQL Server 2008 Management Studio
  2. right click on your database
  3. context menu appears, navigate to Tasks, then "Generate scripts..."
  4. you get a wizard which brings you to a window with the following options:


the only option worth noting is to set "Script Data" to true if you want to copy data with the schema.

The rest is self-explanatory because, well it's a wizard, but now you at least know that this tool exists.