Categories

Archives

A sample text widget

Etiam pulvinar consectetur dolor sed malesuada. Ut convallis euismod dolor nec pretium. Nunc ut tristique massa.

Nam sodales mi vitae dolor ullamcorper et vulputate enim accumsan. Morbi orci magna, tincidunt vitae molestie nec, molestie at mi. Nulla nulla lorem, suscipit in posuere in, interdum non magna.

Stored Procedures and Return Statement

In a recent interview i was been asked whether stored procedures can have “return” keyword and what type of values it can return.

I thought i will note this point here.

Stored Procedures can return value. Only a single numeric value can be returned.
Consider the following snippet.

[code lang=”sql”]

CREATE PROCEDURE dbo.GetCustomerMaxID ()
AS

DECLARE @MAXID INT

SELECT MAX(ID) FROM CUSTOMER

Return @MAXID

[/code]

and we can call the proceduce like this

[code lang=”sql”]

DECLARE @ReturnValue INT
EXEC @ReturnValue = GetCustomerMaxID
SELECT ReturnValue=@ReturnValue
[/code]

and the output looks like this:

[code lang=”sql”]
ReturnValue
———–
33343

(1 row(s) affected)
[/code]

All it does is use the RETURN statement to send back the value that was passed in.

Note The executing a RETURN statement causes a stored procedure to stop executing and return control back to the calling program.

This is often used to test for error conditions and stop processing if one is found.

and we can get the value back in to our C# – ADO.NET code like below

[code lang=”sql”]

public int GetCustomerMaxID()
{

string connectionString =
@"Server=.SQLEXPRESS; Initial Catalog=Northwind; Integrated Security=True;";
using (SqlConnection conn = new SqlConnection(connectionString))
{
using (SqlCommand cmd = new SqlCommand("dbo.GetCustomerMaxID"))
{
cmd.CommandType = CommandType.StoredProcedure;

SqlParameter returnValue = new SqlParameter("@Return_Value", DbType.Int32);
returnValue.Direction = ParameterDirection.ReturnValue;

cmd.Parameters.Add(returnValue);

conn.Open();
cmd.Connection = conn;

cmd.ExecuteNonQuery();

int maxID = Int32.Parse(cmd.Parameters["@Return_Value"].Value.ToString());

conn.Close();

return maxID;
}
}

return 0;
}

[/code]

Have fun!! Happy Coding..

IIS Developer Express or Same Old Cassini

I am trying out the features of newly released Microsoft Web Matrix and IIS Developer Express. I felt it’s cool to have something like this.  I Tried both IIS 7.5 and IIS Developer Express simultaniously working on Windows 7.

I tested it with IIS 5.1 and IIS Developer Express simultaniously working with Windows XP Sp3.

Accidently i located something on my Windows Drive (C: Drive)

I got it,  i got it :-). Isn’t that the SAME OLD CASSINI (Now our ASP.NET INTEGRATED DEVELOPMENT SERVER), in a new shiney bottle and a  nice user  interface.

I think Microsoft forgot to change the folder name from CASINI to something else, So that people will not recognize it as CASSINI and Consider it as Lightweight version of IIS 7.5.

Nice Trick 🙂 ..

PS: It’s  just a thought that’s all. Not intended anything bad or harm to Microsoft  on IIS Developer Express development and features. IIS Developer Express and Asp.NET Web Matrix is really cool tools, every developer needs it nowadays…

Apart from that I really loved it. Really Useful one!!!  Thanks Microsoft!!!

FEATURE SUGGESTION & ISSUES

I would suggest one more feature if possible. Would that be possible to make the Server instance accessible through the network.

For example: If i host a sample site on http://localhost:5252 in IIS Developer Express, is it possible to make it accessible in my team mates system  like http://192.168.13.23:5252  or by System Name. Only for development and internal testing this would have been great.

Could that be possible to Add up microsoft? Really helpful for us.

SSL SUPPORT

It’s not working i think. Would that be a future update?

Microsoft Data Access Application Block Quick Code Snippet

I was just testing through the Microsoft Data Access Application Block 5.0 which is part of Enterprise Library 5.0.

Just thought of sharing the code.

Libraries Needed (Add reference to the following libraries from Enterprise Library 5.0 or 4.x)

Microsoft.Practices.EnterpriseLibrary.Common.dll
Microsoft.Practices.EnterpriseLibrary.Data.dll

Here’s the connection string to be declared

Connection String
[code lang=”xml”]

<add name="NorthwindConnectionString" connectionString="server=(local)sqlexpress;database=Northwind;User ID=nw_user;Password=developer;Application Name=Northwind" providerName="System.Data.SqlClient"/>

[/code]

C# Source Code
[code lang=”c-sharp”]

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.Common;

/* Microsoft Data Accesss Application Block Namespace */
using Microsoft.Practices.EnterpriseLibrary.Data;

namespace WebAppPro1.EntLib
{
/// <summary>
///
/// </summary>
public class DataAccessBlockDemo
{
const string SqlQueryEmployeeGetDetails = "SELECT Distinct FirstName, LastName, JobTitle FROM Employee ";

private const string SqlQueryEmployeeUpdate =
"Update Employee set JobTitle=’Sr.Manager’ where EmployeeID = @EmployeeID ";

private const string SqlQueryEmployeeSalaryUpdate =
"Update [Employee_Salary] set Grade = ‘L3’, SalPkg = ‘25000.00’ where EmployeeID = @EmployeeID";

private const string ConnStringName = "NorthwindConnectionString";

/// <summary>
/// Employees the get details data set.
/// </summary>
/// <returns></returns>
public DataSet EmployeeGetDetailsDataSet()
{
DataSet returnSet = new DataSet();
Database database;

try
{

//Calls the DatabaseFactory.CreateDatabase with the connection string name for the DataBase
//connection specified in the *.config file.

database = DatabaseFactory.CreateDatabase(ConnStringName);

DbCommand dbCommand = database.GetSqlStringCommand(SqlQueryEmployeeGetDetails);

returnSet = database.ExecuteDataSet(dbCommand);

}
catch (Exception exp)
{
return null; //either return null to indicate a null dataset or rethrow exception.
//throw;
}
finally
{
database = null; //This is not necessary actually. Because DAAB manages the connection destroying and establishing etc.
}

return returnSet;
}

/// <summary>
/// Employees the get details sp.
/// </summary>
/// <returns></returns>
public DataSet EmployeeGetDetailsSp()
{
return EmployeeGetDetailsSp(0);
}

/// <summary>
/// Employees the get details sp.
/// </summary>
/// <param name="empId">The emp id.</param>
/// <returns></returns>
public DataSet EmployeeGetDetailsSp(int empId)
{
DataSet returnSet = new DataSet();

try
{
Database db = DatabaseFactory.CreateDatabase();
DbCommand command = db.GetStoredProcCommand("GetEmployeeDetail");

// Define the input parameter for SP with AddInParameter method
db.AddInParameter(command, "@EmployeeID", DbType.Int32, empId); //if empid <= 0, returns all employee details.

// You can Specify output Paramameters like below.
//db.AddOutParameter(_command, "@TotalLeaves", DbType.String, 50);

/* If the stored procedure return any value(single valued), with AddParameter method & ParameterDirection.ReturnValue
*
db.AddParameter(_command, "@ReturnValue", DbType.Int32,
ParameterDirection.ReturnValue, "@ReturnValue", DataRowVersion.Default, null);
*
*/

returnSet = db.ExecuteDataSet(command);

/* will be null if no match found */

//return returnSet;

}
catch (Exception exp)
{
returnSet = null;
}

return returnSet;
}

/// <summary>
/// Updates the employee details transacted.
/// </summary>
public void UpdateEmployeeDetailsTransacted()
{
Database database = DatabaseFactory.CreateDatabase();

//comm
DbCommand cmdUpdateEmployee = database.GetSqlStringCommand(SqlQueryEmployeeUpdate);

DbCommand cmdUpdateEmployeeSalary = database.GetSqlStringCommand(SqlQueryEmployeeSalaryUpdate);

using (DbConnection dataConnection = database.CreateConnection())
{
dataConnection.Open();

/* Start a transaction by calling BeginTransaction method on the
* connection object created above*/

DbTransaction dbTransaction = dataConnection.BeginTransaction();

try
{
//Calling Updating Employee Designation. If designation update is successful, we will update his salary
database.ExecuteNonQuery(cmdUpdateEmployee, dbTransaction);

//Calling Updating Employee Salary Package
database.ExecuteNonQuery(cmdUpdateEmployeeSalary, dbTransaction);

//both update was successful so committing the transaction.
dbTransaction.Commit();
}
catch (Exception exp)
{
//Oohh!! Some exception happened lets roll back….
dbTransaction.Rollback();
}

//Hey close me — ( Not necessary some times. "Using" will do it.)
dataConnection.Close();
}
}
}
}

[/code]

Can i tell one benefit of using this code. You can just simply change to a new data source (stored procedure supprt i am not sure, cross database does it supports? need to test). But normal text query i have tested in MS ACCESS and Oracle Client setting like below connection strings.

For MS ACCESS DB
[code lang=”xml”]

<add name="NorthwindConnectionString" connectionString="Provider=Microsoft.Jet.OLEDB.4.0; User ID=myuser; Data Source=|DataDirectory|northwind.mdb; Password=" providerName="System.Data.OleDb"/>
[/code]

For ORACLE DB
[code lang=”xml”]
<add name="NorthwindConnectionString" connectionString="Data Source=Oracle8i; Integrated Security=SSPI" providerName="System.Data.OracleClient"/>
[/code]

Since Micrsoft DAAB uses the ADO.NET DatabaseFactory classes and we uses DAAB defined classes, it would be easy for us to Migrating to different Data Source.

That’s all for now. I hope this information helps.

Happy Coding !!! Enjoy the Day!!!

Windows Live Writer Testing phase–Trial 001

Hey there how are you today..

 

Superb. I Love Windows live writer and wordpress working smoothly..

Introducing Microsoft WebMatrix (IIS Developer Express,ASP.NET Razor, SQL Server Compact)

There was a time initially when Microsoft has released the ASP.NET 1.0 and 1.1, they have released a free ASP.NET development tool called ASP.NET Web Matrix. I remember doing lot of fancy stuffs with it. My initial days i had a craze about that thing. Pretty awsome doing development with it, light weight

Web Matrix grew out of a pet project started by Nikhil Kothari. It was originally conceived as a test bed for working with ASP.NET controls in a designer environment. The ASP.NET team saw a number of benefits for a tool of this type, and used it to try out a variety of additional ideas for creating an IDE that could act as a lightweight alternative to Visual Studio. The project was developed into a product (originally code-named “Saturn”) that was released in the summer of 2002 as free download on the www.asp.net Web site, without official support (only community support) and with only word-of-mouth marketing. The original release supported only Microsoft SQL Server, which was bundled with Web Matrix in the form of MSDE, a desktop version of the database engine. A subsequent release of Web Matrix (“Web Matrix Reloaded“) in June 2003 included support for Microsoft Access .mdb files, which simplified deployment.

Web Matrix included a number of features that made it an appealing alternative to Visual Studio 2003:

  • It was a comparatively small download and was fast and easy to install.
  • It was specific to Web applications, thus avoiding some of the complexities required in Visual Studio to support the different tools, languages, and application types in Visual Studio.
  • It used a folder-based model, rather than the project model used in Visual Studio. (For more information, see Scott Guthrie‘s blog entry VS 2005 Web Project System: What is it and why did we do it?.)
  • It did not require design-time compilation into a single deployable .dll. Instead, developers could deploy the source code for their ASP.NET pages and rely on ASP.NET to dynamically compile the pages on first request.
  • It included a small Web-server tool (“Cassini”) that ran on the local computer and enabled the developer to test ASP.NET Web pages without requiring Internet Information Services. This feature made it appealing to developers who could not run IIS due to corporate policy or because they did not have a version of Microsoft Windows that includes IIS.
  • It included FTP support, rather than requiring FrontPage Server Extensions (FPSE). This feature made it a practical development tool for hobbyists and students who could develop and test on their own computer, and then deploy their files to a hosted server.
  • It was free.

Many of these features were incorporated into Visual Studio 2005, and the Web Matrix style of web application development became the default. The success of the Web Matrix project, both in terms of features and in the appeal to the community of a free IDE with a limited feature set, also helped the Visual Studio team decide to release free lightweight versions of Visual Studio 2005—Visual Web Developer Express Edition for Web development, and similar Express versions of Visual Basic, C#, and SQL Server.

Later for a while we didnt hear about WebMatrix… Suddenly microsoft yesterday July 7th announced the availability of their new web development suite called Web Matrix. Ohh!! I felt is n’t that old Web Matrix or a new flavour lets see.

The NEW Shiney – Microsoft WebMatrix Web development suite

WebMatrix combines the three products revealed last week by ScottGu—IIS Developer ExpressSQL Server Compact Edition, and ASP.NET “Razor”—with a new lightweight development environment. The new tool integrates support for these products, to provide streamlined deployment to the development web server, database management, and page creation. To this it adds built-in support for publishing to a range of hosting providers, libraries to automate common tasks, and a repository of open-source web applications that can be downloaded and incorporated into a project automatically.

IIS Developer Express gives developers a standalone version of the IIS 7.5 web server that ships with Windows Server 2008 R2 and Windows 7. Traditionally, ASP.NET developers have had to choose between the convenience of Visual Studio’s ASP.NET Development Server, which runs as a regular user account and has easy deployment integration with Visual Studio, but which lacks the full range of IIS’s features, or the version of IIS that ships with their version of Windows. For developers on Windows XP this is particularly problematic, as the version that ships with that operating system does not correspond to any “real” server version. With IIS Developer Express, developers can develop against, and test on, a web server that’s fully compatible with the full IIS 7.5 server, but which retains the ease of use and convenience of the ASP.NET Development Service.

SQL Server Compact Edition 4 provides a SQL Server-compatible database that requires no installation and which uses regular files to store its data. The database engine itself within the web application; when that is stopped, so is the database. Just as with IIS Developer Edition, this enables development without the use of Administrator accounts or the administrative burden of using “real” SQL Server. Both versions promise the ability to migrate to their respective “regular” versions with no code changes necessary. SQL Server Compact Edition has been around for some years; version 4 marks the first release that’s suitable for use in multithreaded server applications.

ASP.NET “Razor” is a new templating language for ASP.NET, designed to be simpler and more streamlined than traditional ASP.NET development. The first release of WebMatrix does not include Razor; it will ship in an update in the coming months.

The WebMatrix development environment ties these things together. Pages can be written using ASP.NET (or, when released, Razor), then deployed to IIS Development Express for testing. WebMatrix can be used to inspect and alter database tables and data. When ready, the project can be deployed using FTP or Microsoft’s Web Deploy infrastructure to a production environment or third-party hosting.

PS: You have to download  Microsoft Web Platform Installer 3.0 BETA to install Web Matrix in your PC.

I really welcome and celebrate announcement of such a nice package. 🙂 . This is just an information sharing blog.

Information Courtesy : Wikipedia , Ars Technica

ASP.NET Web Pages with Razor Syntax and IIS Developer Express Download

ASP.NET Web Pages with Razor Syntax is a web framework and part of WebMatrix. WebMatrix is everything you need to build Web sites using Windows. It includes IIS Developer Express (a development Web server), ASP.NET (a Web framework), and SQL Server Compact (an embedded database). It streamlines Web site development and makes it easy to start Web sites from popular open-source apps. The skills and code you develop with WebMatrix transition seamlessly to Visual Studio and SQL Server.

Download From Microsoft Download Center

For installing Microsoft Web Matrix, you have to get Microsoft Web Platform Installer 3.0 BETA 1, through which you can have Microsoft WebMatrix and necessary components for start working..
Microsoft WebMatric Download
Web Matrix Home

Note: It’s not a final download. BETA..