[PowerShell] How to Retrieve Data with ADO.NET

I am primary a C# developer since 2005. Before that I was a VB5/VB6/VB.NET developer. Recent, I changed my role from development side to a consulting side. I found out that I have to do some development by using powershell script. It is because I will pass the program to client and we should try to build with script or any “no compile needed language”. And so I start writing PowerShell script. Because of this, I will write some blog about PowerShell  that I learned from my job. And this is the first one in this series.

My first PowerShell task is, retrieve data from MSSQL.

From my C# knowledge, I would like to retrieve data by using ADO.NET. So I start looking for how I could use C# library in PowerShell Script. And lucky that there is a way.

Below is my first script in PowerShell.

Function GetDataFromMSSQL {
    Write-Host "====================================="
    $sqlConn = New-Object System.Data.SqlClient.SqlConnection
    $sqlConn.ConnectionString = "Server=localhost;Integrated Security=true;Initial Catalog=AdventureWorks2019;"
    
    try {
        $sqlConn.Open()
        Write-Host "Data Source is connected."
        #$sqlcmd = $sqlConn.CreateCommand()
        $sqlcmd = New-Object System.Data.SqlClient.SqlCommand
        $sqlcmd.Connection = $sqlConn
        #$selectQuery = "SELECT TOP (1000) [SpecialOfferID],[Description],[DiscountPct],[MinQty],[MaxQty] FROM [AdventureWorks2019].[Sales].[SpecialOffer]"
        $sqlcmd.CommandText = $selectQuery

        $sqladp = New-Object System.Data.SqlClient.SqlDataAdapter $sqlcmd
        $data = New-Object System.Data.DataSet
        $sqladp.Fill($data) | Out-Null

        $rowCount = $data.Tables[0].Rows.Count
        Write-Host "$rowCount rows returned."
        $data.Tables
        $true
    } catch {
        Write-Host "Data Source cannot be connected."
        Write-Host $Error[0].Exception.Message
        $false
    } finally {
        $sqlConn.Close()
    }
}
GetDataFromMSSQL

 

The new features introduced in each version for C# (1.0 – 5.0)

Last week I have a gathering with all current and ex-HK MVPs. During the dinner, we talked about what is the difference between each new version of C#. Please allow me to have a short summary of this topic into a picture. You are welcome to share this picture to your friends, your user group, your colleagues.

P.S. Noted that Microsoft has just announced that VS2013 will be coming soon, I will come back to this once it is Release or in Beta.

 

 

MVC Performance in IIS – Part II

Last 2 weeks, I run MVC training kit to IIS 7.5 and was trying to figure out the baseline for the performance tuning for my project. I tested 3 Scenarios,

S1) Hosting MVC 1.0 Training Kit in Application under Default Website
S2) Hosting MVC 1.0 Training Kit in New Website with port 8081
S3) Hosting my company’s MVC Project in New Website with port 8082

And their result of max throughput on Default Page is around,

Result 1 Screen Shot
R1 Result Screen Shot

Result 2 Screen shot
R2 Result Screen Shot

R1) ~200/sec
R2) ~2980/sec
R3) ~410/sec

This time, I tested in more scenarios,

S4) Moving MVC 1.0 Training Kit to root of Default Website
S5) Hosting MVC 1.0 Training Kit in Application under New Website with port 8081
S6) Hosting my company’s MVC Project in Root of Default Website

And their result now are,

Result 4 Screen shot
R4 Result Screen Shot

Result 5 Screen Shot
R5 Result Screen Shot

Result 6 Screen shot
R6 Result Screen Shot

R4) ~225/sec
R5) ~2650/sec
R6) ~170/sec

OK, let me group the result in a table and so we could view all results more clear.

  In Root In Application
MVC 1.0 Kit in Default Website ~225/sec ~200/sec
MVC 1.0 Kit in New Website with port 8081 ~2980/sec ~2650/sec
Company MVC Project in Default Website n/a ~170/sec
Company MVC Project in New Website with port 8082 ~410/sec n/a

Now the results are showing that
1) The performance will be gained about 10% if you move the MVC project from Application under website into root of website.
2) The performance will be gained in a range from 240% – 1325%  if you move the MVC project from Default Webste to New Website.

Windows Azure Services

Windows® Azure is a cloud services operating system that serves as the development, service hosting and service management environment for the Azure Services Platform. Windows Azure provides developers with on-demand compute and storage to host, scale, and manage Web applications on the Internet through Microsoft® data centers.

To build these applications and services, developers can use their existing Microsoft® Visual Studio® 2008 expertise. In addition, Windows Azure supports popular standards and protocols including SOAP, REST, and XML. Windows Azure is an open platform that will support both Microsoft and non-Microsoft languages and environments. What is the Azure Services Platform?

[Microsoft Live Labs] Volta: Web Development Using Only the Materials in the Room

 


Today, Microsoft Live Labs is announcing the Volta technology preview, a developer toolset for building multi-tier web applications using existing and familiar tools, techniques and patterns. Volta’s declarative tier-splitting enables developers to postpone architectural decisions about distribution until the last possible responsible moment. Also, thanks to a shared programming model across multiple-tiers, Volta enables new end-to-end profiling and testing for higher levels of application performance, robustness, and reliability. Using the declarative tier-splitting, developers can refine architectural decisions based on this profiling data. This saves time and costs associated with manual refactoring. In effect, Volta extends the .NET platform to further enable the development of software+services applications, using existing and familiar tools and techniques.


You architect and build your application as a .NET client application, assigning the portions of the application that run on the server tier and client tier late in the development process. You can target either web browsers or the CLR as clients and Volta handles the complexities of tier-splitting. The compiler creates cross-browser JavaScript for the client tier, web services for the server tier, and all communication, serialization, synchronization, security, and other boilerplate code to tie the tiers together. In effect, Volta offers a best-effort experience in multiple environments without requiring tailoring of the application.