Wednesday, February 26, 2014

Microsoft.SqlServer.Management.SMO

Hi All,

I’ve been using SMO heavily in my OSR data migration piece of work, and I’d like to share that with you.  To put SMO into context, I consider it as a programmatic way to interact with SSMS.
For CRUD actions, SqlClient is still very good. Very flexible compared to entity framework.
However, when we need extra flexibility, e.g., create/backup database, create/alter tables, especially running SQL with GO statement, SMO is the way to go.   

I’ve attached a Util class that demonstrates how it can be wrapped, and the dynamic SQL that gets generated by my program and executed via the Util class.

If you would like to know more, plenty of articles on MSND:
SQL Server Management Objects (SMO) is a collection of objects that are designed for programming all aspects of managing Microsoft SQL Server


Sqlserver nvarchar ntext difference

Thanks to Graeme for asking an interesting question about the difference between nvarchar and varchar. Since my first language can’t be stored in ACSII, I know nvarchar is the way to go.
Further reading on nvarchar(max) prompted us to think the differences between nvarchar and ntext, and we found the following in MSDN. 

ntext , text, and image data types will be removed in a future version of Microsoft SQL Server. Avoid using these data types in new development work, and plan to modify applications that currently use them. Use nvarchar(max), varchar(max), and varbinary(max) instead.

Don’t panic, further version doesn’t include SQLServer 2012.  Read more here:

.Net Entity Framework and DAL

This old post demonstrates some very interesting thoughts about DAL and Entity Framework, and discussed the design pattern (pros and cons) in an architecture point of view. At the last of this post, a ppt is embedded. http://www.wadewegner.com/2009/06/architecting-your-data-access-layer-with-the-entity-framework/
Here are some highlights and my understanding:
·         Use EF as DAL  This is still a good option to replace the CRUD. See my OpsLog comments below about EF.
·         Full Encapsulation of the Entity Framework.  This is the ideal solution but we probably won’t get to the complexity. It reduces coupling and make application testable.
·         Partial Encapsulation of the Entity Framework.  The author didn’t give an example, but I have some in EGMAN.  EGMAN uses MVC and MVVM (MVVM Model-View ViewModel is similar to MVC, Model-View Controller).  I used EF to map db to model (M in MVC), but sometimes lost the flexibility to add custom attribute and data access logic. I adopted MVVM, which use VM to replace C, and VM is the encapsulation of EF that extract data from the Model. 

Links of the month November

Links of the Month November

OpenXML: New and easiest way to do handle MS Office document on server (eg, mailmerge)
·         Example: TFS $ActewAGL.MailMerge
·         Download: http://www.microsoft.com/en-us/download/details.aspx?id=5124
·         Read More

Asp.NET MVC: A mindset change to build testable website
·         Office Website with very good tutorials
·         Sample website with 200+ pages of step by step guild on how to build the website, MVC Music Store
LINQ:  Jon Skeet re-implement LINQ in 45 posts. Download the ebook and learn.
Tools
·         Telerik Extensios for ASP.NET MVC: free open source controls for MVC. Every control come with full sample code and demo.
·         .Net Demon: Tool that build as you type
·         NCrunch similar to .Net Demon, but also do continuous testing.
·         Both tools Combine with LiveReload (and Chrome extension), No more F6 to build, and F5 to refresh
·         VS 2012 & TFS 2012 update 1 released.  Visual Studio 2012 Update 1 focuses on enhancements to SharePoint development, Windows development, continuous quality enablement, and tools for agile teams.
·         Together with update 1 release, MS also released VS2010 Application Lifecycle Management Virtual Machine and Hands-on-Labs.  It’s really time to upgrade!
Latest
·         I won’t tell you what this is, you so have to click to find out. http://www.microsoft.com/australia/ws2012xbox/
·         Announcing the Latest Release of Office Developer Tools
·         Video:  Bleeding edge ASP.NET: See what is next for MVC, Web API, SignalR and more…
·         Microsoft Releases SkyDrive SDKs for .NET, Windows Phone 8
·         HTML5 and Why Developers Need It (IE8 support 0% of its’ feature)
·       Finally: Windows (Phone/Tablet) 8 : Too many posts out there

scrum

     After three days of training on scrum, I'd like to share few tips and materials.
Scrum is simple to understand, hard to implement. It is the most popular agile methodology. Few things I like about it:

* Daily Scrum (also referred as daily stand-up, but what if Zhen broke his knee and can't stand):  is a good way to synchronise between team members. It is not a free form, and 3 questions are answered by every team member.  (was working, plan to work, any impediment)
* Retrospective: is the best part in my opinion. Every team member answer three questions, what went well, want went wrong, how to improve. The lecture said he used this to coach his kids soccer team :)

* Working in the order of priority, and deliver business value in each sprint. 

links of the month October

Links of the Month October

MEF
·         Managed Extensibility Framework (MEF)
·         MEF An interesting documentation with examples
·         MEF vs IoC

Working with Data
·         Overview of Data Development platform in .Net

Tools
·         LinqPad A combination of c# and SMSS
·         Database Comparison Tool:  DBComparer
·         TFS2012 Reasons to Upgrade
Latest
·         Team Foundation Service is Released   A version of Team Foundation Server hosted on Windows Azure. Free for MSDN subscribers!
·         When JavaScript is unmanageable: Introducing Typescript
·         Typescript - a real world story of adoption in TFS 160K line of JavaScript
·         Key Windows 8 Developer Tenets and Skills

.Net tools

  • ·         NuGet Package Manager: NuGet is a Visual Studio extension that makes it easy to install and update third-party libraries and tools in Visual Studio. You can install all of the library discussed here from within NuGet
  • ·         AjaxControlToolkit:  http://www.asp.net/ajaxlibrary/AjaxControlToolkitSampleSite/ An open-source project built on top of the Ms ASP.NET AJAX framework. It contains more than 30 controls that enable you to easily create rich, interactive web pages. Eg, Calendar, ModalPopup, AsyncFileUpload
  • ·         ELMAH: Error Logging Modules and Handlers is an application-wide error logging facility that is completely pluggable. Tutorial: http://www.asp.net/web-forms/tutorials/deployment/deploying-web-site-projects/Logging-Error-Details-with-ELMAH-cs
  • ·         JQuery, JQuery UI & plugins,: More than 55% of the world most visited 10000 website use JQuery. Why shouldn’t we use it?
  • ·         Json: JavaScript Object Notation is a text format, lightweight data-interchange format. A Fat-Free Alternative to XML.
  • ·         Json.NET: Json.NET is a popular high-performance JSON framework for .NET. see http://james.newtonking.com/pages/json-net.aspx for details.
  • ·         EF:

o   Microsoft product, we know what is means.
o   Highly Supported and plenty of resources online, with fairly strong communities online. Evolving very fast, fixes was coming out very fast and it was getting better day by day.
o   LINQ.  No more CRUD.
o   Lower learning curve than Nhibernate.
o   Database Frist has more features than Code First

o   Easy to code and maintain compared to Dataset

Links of the month September

Microsoft Developer Links of the Month


·         Debug production system: Visual Studio Ultimate 2012: Collecting and analyzing data in production
·         TFS put into good use: Automated Build-Deploy-Test using TFS 2012
·         Visual Studio New features: Visual Studio 2012: Did You Call Me?
·         Reason not to test? None: Testing for Continuous Development
·         ASP.NET improvements continue: Introducing ASP.NET FriendlyUrls - cleaner URLs, easier Routing, and Mobile Views for ASP.NET Web Forms and ASP.NET 4.5 ScriptManager Improvements in WebForms
·         Windows Azure new features: Meet the New Windows Azure and a follow up article Announcing: Great Improvements to Windows Azure Web Sites
·         Win8: Reasons Why You Should Develop a Windows 8 App
·         Webcast: How Google Tests Software & Getting Started with Windows Azure

Want something Free?

How to check a process or program is running via powershell script

Powershell script to check if a program is running or not

$Prog = "C:\Program Files (x86)\Mozilla Firefox\firefox.exe"
$Running = Get-Process firefox -ErrorAction SilentlyContinue
$Start = {([wmiclass]"win32_process").Create($Prog)}
if($Running -eq $null) # evaluating if the program is running
{& $Start} # the process is created on this line