Friday, May 11, 2007
Microsoft SQL Server "Katmai" (Next Release after SQL Server 2005)
Microsoft stated:
Katmai will help companies access and manage rapidly increasing volumes of data for mission-critical applications, increase their ability to better understand the organization with business insight, and reduce difficulties associated with managing complex systems. SQL Server “Katmai” builds on the success of SQL Server 2005 as a proven platform that is crucial to the completion of business projects, delivering increased functionality to a comprehensive range of applications from the desktop to the data center.
Ted Kummert, corporate vice president of the Data and Storage Platform Division at Microsoft, said:
“We developed SQL Server with the goal of providing a data management and analysis platform for all companies regardless of size or budget, With the release of ‘Katmai,’ we’ll take the next step on our data platform vision by delivering a comprehensive and integrated business intelligence solution. Expanding the usability of data across businesses will give customers more value for their IT investments.”
Few Important links for Katmai:
http://www.microsoft.com/sql/prodinfo/futureversion/default.mspx
http://www.microsoft.com/presspass/press/2007/may07/05-09KatmaiPR.mspx
http://download.microsoft.com/download/B/F/2/BF24C54E-5635-4C79-AFB4-0C3F840E79F4/Katmai_datasheet_Final.pdf
Wednesday, December 20, 2006
System.Collections.Generic
Example:
using System;
using System.Collections.Generic;
class GenericDemo
{
public static void Main()
{
List
//Add elements to generic integer list
//Correct entry as per generic
lstInteger.Add(1);
lstInteger.Add(2);
lstInteger.Add(3);
lstInteger.Add(4);
lstInteger.Add(5);
//Code exception due to following wrong entry
lstInteger.Add(‘Kuldeep’);
}
}
Because of type-safety principle, in above example it will throw error at last lstInteger.Add(‘Kuldeep’) statement. Current declaration for generic is an integer and at last statement you'r trying to insert is a string type. So it will raise exception.
Tuesday, December 19, 2006
The Mutex (C# - Threading)
Mutex is used to set exclusive access on shared resources in multi-thread programs. This means only one thread can access shared object at a time. A mutex is a perfect synchronization mechanism in C# threading.
Consider a example of when two threads accessing same system resources like files, system registry, Environment variables, etc. And you want to put exclusive access in multithreaded environment on shared resources then this can be achieved using mutex.
System.Thread.Mutex Class:
Above class supports Mutex.
To acquire Mutex call WaitOne()
To release Mutex call ReleaseMutex()
Example:
using System.Threading;
Mutex objMutex = new Mutex();
//Some code goes here
objMutex.WaitOne(); //Acquire
//Code to get exclusive access
//.....
objMutex.ReleaseMutex(); //Release
Mutex Code Snippet:
using System.Threading;
class FileAccess
{
public static Mutex mtx = new Mutex(); //Mutex variable
//Method to read/write in File
}
class FirstThread
{
public Thread t1;
//Uses above class method to R/W file
FirstThread()
{
t1= new Thread(this.CallFileWrite);
t1.Start();
}
void CallFileWrite()
{
FileAccess.mtx.WaitOne();
Console.WriteLine(“t1: In Mutex ”);
//File writing code ......
Console.WriteLine(“t1: Out Mutex ”);
FileAccess.mtx.ReleaseMutex();
}
}
}
class SecondThread
{
public Thread t2;
//Uses above class method to R/W file
SecondThread()
{
t2= New Thread(this.CallFileWrite);
t2.Start();
}
void CallFileWrite()
{
FileAccess.mtx.WaitOne();
Console.WriteLine(“t2: In Mutex ”);
//File writing code ...... for same file in t1 thread
Console.WriteLine(“t2: Out Mutex ”);
FileAccess.mtx.ReleaseMutex();
}
}
class MutexExample
{
void main()
{
FirstThread mFt1 = new FirstThread();
SecondThread mSt2 = new SecondThread();
MFt1.t1.Join();
MSt2.t2.Join();
}
}
Exception Handling in C#
Exception class is used to handle errors occurred during execution of code. Following are public members of exception class:
HelpLink : Used to set help link for exception.
InnerException: Gets the exception instance that caused the current exception.
Message: Exception description.
Source: Object that caused exception
StackTrace: Call stack for occurred exception.
TargetSite: Method that throws the exception.
Simple exception handling code block:
try
{
// Code statements.
}
catch(Type x)
{
// handling of the exception
}
finally
{
//cleanup code (if any)
}
Note: Catch block is optional in C#. And Finally block always execute.
Multiple Catch Blocks: (All good Programs must be able to uniformly handle errors that occur during code execution.)
try
{
//Your code goes here
}
catch(DivideByZeroException dz)
{
//Divide by zero exceptions will be handled here.
}
catch(OutOfMemoryException oe)
{
//Out of memory exceptions will be handled here.
}
catch(NullReferenceException ee)
{
//Null refernce exceptions will be handled here.
}
catch(Exception ex)
{
//Unknown exceptions from above 3 types will be handled here.
}
finally
{
//Always executes at the end.
}
Some Other Exception types:
IndexOutOfRangeException (Occures in looping when Index is out of range)
InvalidOperationException (Thrown by methods when in an invalid state.)
ArgumentNullException (Thrown by methods that do not allow an argument to be null.)
ComException (COM components)
InvalidCastException
ArithmeticException
SqlException (For DB related exceptions)
ApplicationException Class:
If you are designing an application that needs to create its own exceptions, derive from the ApplicationException class. ApplicationException extends Exception class.
To know more about structured and ApplicatioException handling goto http://www.devcity.net/Articles/284/1/article.aspx (This is supported by Microsoft)
Best practices to handling exceptions:
URL:
Sunday, October 15, 2006
Building Easy Navigation Using the ASP.NET 2.0 MultiView and Wizard Controls
Monday, October 02, 2006
The Development Tools for .NET Framework 3.0 : " Orcas "
Visit URL for download Orcas:
http://www.microsoft.com/downloads/details.aspx?FamilyID=cc77abfa-a000-48d0-98c9-4ae083033d09&DisplayLang=en
Thursday, September 21, 2006
Why SOA?
2. Agile development
3. Removes complexity
4. Supplies common programming interface and interoperability protocol
5. Easy up-gradation
6. Lead towards automated business automation
7. Based on XML
8. Web service platform
9. Reusability
10. Loosely coupled
11. Ease in integration process.
12. Able to leverage existing application and infrastructure
13. Less maintenance cost involved.
14. Reduces hardware cost.
15. Leverage existing development skills
16. Faster application development.
17. Eliminate redundant systems and architecture.
18. Reduce project risk
19. Secured.
20. Flexibility
Sunday, September 03, 2006
Brief on SOA:
The buzzword SOA means Service Oriented Architecture. SOA is loosely coupled in nature. It based on SOAP (Simple Object Access Protocol). As per World Wide Web Consortium (W3C) SOA is 'A set of components which can be invoked, and whose interface descriptions can be published and discovered'.
By using SOA architecture it is possible to develop abstract, reusable, relevant, standard, consumable and standardized solutions.SOA plays major role in enterprise level integration.
Saturday, September 02, 2006
Article: Data Binding and Static Items in List Controls
In this article Kuldeep Deokule shows you how to add static items while implementing data binding on list controls.
Introduction:
ListControl is the abstract class for all list type controls (System.Web.UI.WebControls.ListControl). These list type controls are CheckboxList, DropdownList, Listbox, RadiobuttonList. The properties of the ListControl class allow you to specify the source of the data to populate the list controls. Use the DataSource property to specify the data source to bind to the list controls. Consider the scenario, you’ve a DropdownList control on a web form that is binded to datasource control like SqlDataSource or ObjectDataSource. DropdownList will populate with list of newsletters.
Now, as a good developer you’ve added functionality to select multiple items in DropdownList control by holding control key down. But suppose some user want to receive all newsletters. If you say to user, select all newsletters one by one by holding control key down. This will become very tedious process for any user. User will hate to do this task. So now you want to add one static item “Send All Newsletters” as a top item in the DropdownList. So if user wants to receive all newsletters, user will just select one item. One more design point is on a web page Newsletters DropdownList field is an optional selection for user. So it is impossible to create a DropdownList that doesn’t have a selected item. At least one item in DropdownList control is always selected. So you decided to add one more item in DropdownList control as “Select”. This will be top and default item in DropdownList control.
But due to data binding limitation, “Select” and “Send All Newsletters” list items will be destroyed when you run the web page. Only fetched newsletters from database will be available in DropdownList control. So how to solve this problem?
Solution:
Data source controls make developers life easier but in some case they cannot go beyond bounds specified. It is a limitation of data source controls that they destroy static items created earlier. Most websites need static items in list type controls.
To work out with this problem some developers like to add static items to database directly. But it is not a good idea. These items will unnecessarily reflect in every report related to newsletters table.
Some experienced developers put UNION query in SelectCommand of the data source controls like shown below:
SELECT ‘(Send All Newsletters)’ as AllNewsLetters
UNION
SELECT DISTINCT Newsletters FROM Newsletters
Again above UNION query is not a good idea. By doing this you are adding presentation logic details to data layer, which is not a good programming practice.
It is a weakness of data binding model that you cannot add static items. But static items are required in many cases in list type controls. So what is a good solution to solve above problem? Just take a look at following steps to solve the problem:
1. Add DropdownList control to web form.
2. Do not set any data source control to it through property window or using smart tag.
3. Add Page_Load event in code behind file as show below:
Private Sub Page_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
'Set up the data binding.
NewsletterList.DataSource = SqlDataSource1
NewsletterList.DataTextField = "newsletter"
NewsletterList.DataValueField = "id"
NewsletterList.DataBind()
'Add following items and select the first item by default.
NewsletterList.Items.Insert(0, "Select")
NewsletterList.Items.Insert(1, "Send All Newsletters")
NewsletterList.SelectedIndex=0
End If
End Sub
Now browse the web page. All static and dynamic items are present in DropdownList control. Insert method with position value add items in DropdownList control at appropriate locations. Code line NewsletterList.SelectedIndex=0 cause to select top item as a default item for DropdownList control. Instead of SqlDataSource control you can also use ObjectDataSource control for data binding purpose. Code will remain same for both data source controls only DataSource attribute will change to respective control name.
AppendDataBoundItems Property in ASP.NET 2.0:
ASP.NET 2.0 exposes AppendDataBoundItems property for all list type controls. This property make this task little easier. If AppendDataBoundItems property is set to true for DropdownList control. Then added static items are not destroyed at the time of page load.
Just take look at following code:
Private Sub Page_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
'Set up the data binding.
NewsletterList.Items.Add("Select")
NewsletterList.Items.Add("Send All Newsletters")
NewsletterList.AppendDataBoundItems = True
NewsletterList.DataSource = SqlDataSource1
NewsletterList.DataTextField = "newsletter"
NewsletterList.DataValueField = "id"
NewsletterList.DataBind()
NewsletterList.SelectedIndex=0
End If
End Sub
If you set AppendDataBoundItems property to False then all static items will be destroyed. Value of AppendDataBoundItems is stored in view state.
So AppendDataBoundItems will do all magic for us. AppendDataBoundItems is only available in .NET framework 2.0. So for ASP.NET 1.x this solution will not work.
Conclusion:
In this way we can go beyond the limits of data source controls. Above solutions will help you to add static items to data bound list type controls.
Wednesday, July 12, 2006
New blog is started on DNS. Please visit following link:
http://dotnetslackers.com/community/blogs/kuldeepdeokule/
Thursday, July 06, 2006
Download presentations in TechEd 2006 !!!
To download presentations in TechEd 2006 visit following links:
http://www.wintoolzone.com/showpage.aspx?url%3dhttp://www.wintoolzone.com/Presentations.aspx
Thursday, June 15, 2006
What is in .NET 3.0?
1. .NET Framework 2.0
Common Language Runtime (CLR)
Base Class Library
ADO.NET 2.0, ASP.NET 2.0, Windows Forms 2.0
VB 8.0 and C# 2.0
2. WinFX
Windows Communication Foundation (WCF)
Windows Presentation Foundation (WPF)
Windows Workflow Foundation (WF)
3. InfoCard
Renamed to Windows CardSpace (WCS)
WinFX is useful to build SOA(Sevice Oriented Architecture), n-tier, etc...
IMP: .NET 2.0 Framework and compilers are unchanged, so your existing code will continue to run as it exists today in .NET 3.0
Tuesday, June 13, 2006
Saturday, June 10, 2006
Building a 3-tier Architecture Using the ObjectDataSource in ASP.NET 2.0
Abstract
ASP.NET 2.0 has introduced a series of new data source controls that simplify the life of developers. Developers can now connect to a database and perform CRUD operations with a minimal amount of code or in some cases no code at all. To enable developers to insert business logic into their applications the new ObjectDataSource control is provided in ASP.NET 2.0. In this article Kuldeep Deokule will use an example Employee listing application to show how to incorporate business logic in a 3 tier application using the new ObjectDataSource control. more...
Tuesday, June 06, 2006
What is Obfuscation?
Microsoft .NET platform uses MSIL (Microsoft Intermediate Language) to produce executable code. This MSIL is higher level in nature than machine code.
One can use a de-compiler program to reverse engineer .NET applications. That means your source code is not safe. Here obfuscation technique comes in focus. To stop reverse engineering of .NET applications obfuscation can be used. It is not a encryption technique. Obfuscation convert meaningful terms in source code to non-meaningful. For example your source code contains variables named intEmployeeId, intNoofChildern, etc then these variable names converted to a, b, etc.
So due to obfuscation implementation source code becomes difficult to understand. Obfuscation is not a 100% proof technique to stop reverse engineering on your source code. But it makes your .NET application source code more secure.
Obfuscation technique even renames the names of methods, properties, functions, procedures, and events to meaning-less names. At the same time obfuscation take care of application’s performance. It is not affected due to obfuscation implementation. It keep your application intact.
Microsoft Visual Studio provides Dotfuscator tool to perform obfuscation since it 2003 release.
Saturday, May 13, 2006
Steps to Configure SQL Cache Invalidation
To configure SQL cache invalidation two steps are required, first configure SQL server to cache invalidation and second add configuration information in “caching” section under “system.web” in web.config file.
Following are the important steps to configure SQL server:
I’ve used database named “Payroll”. In payroll, I am going to set SQL cache validation on “Employee” table which contains detailed information of working employees.
1. Open Visual Studio .NET 2005 command prompt. (By navigating to Microsoft Visual Studio 2005 -> Visual Studio Tools -> Visual Studio .NET 2005 Command Prompt)
2. Use aspnet_regsql tool to enable SQL cache invalidation. The aspnet_regsql tool is present in your Windows\Microsoft.NET\Framework\[version] folder. Use command prompt to navigate for this folder.
3. To enable SQL cache invalidation on payroll table in SQL Server issue following command.
aspnet_regsql -E -d Payroll –ed
Press enter to execute the command.
Following is the information about options used with aspnet_regsql command:
-E: Used to enable integrated security when connecting to your database server.
-d: Used to select the Payroll database.
-ed: Used to enable the database for SQL Cache Invalidation.
payroll: It is the name of database.
After successful execution of an above command AspNet_SqlCacheTablesForChangeNotification, new table is added to the payroll database. This table contains a list of all of the database tables that are enabled for SQL cache invalidation. Some new stored procedures are also added to the database.
4. Now select a table in payroll database for SQL cache invalidation. Let’s select “Employee” table.
aspnet_regsql -E -d Payroll -t Employee –et
Following is the information about option used in above commands:
-t: Used to select a database table. In my case it is Employee table.
-et: Used to enable a database table for SQL cache invalidation.
To enable cache invalidation for multiple tables re-execute this command for each database table.
This command adds trigger to database table. Trigger fires whenever changes are occurred in that table.
By doing above steps configuration at SQL server is complete here. But second part is still remaining that is adding some entries in web.config file without this caching won’t work even if you configured it for SQL Server.
File Name: web.config
<configuration>
<connectionStrings>
<add name="PayrollConnection"
connectionString="Server=localhost;Database=Payroll" />
</connectionStrings>
<system.web>
<caching>
<sqlCacheDependency enabled="true">
<databases>
<add name="Payroll"
connectionStringName="PayrollConnection"
pollTime="50000" />
</databases>
</sqlCacheDependency>
</caching>
</system.web>
</configuration>
Friday, April 28, 2006
Difference between SqlDataSource and ObjectDataSource
1. SqlDataSource is two-tier in nature where as ObjectDataSource supports three-tier architecture.
2. SqlDataSource requires very small amount of coding to connect with database. For ObjectDataSource more coding is required to build data access class.
3. SqlDataSource not support full encapsulation. ObjectDataSource supports full encapsulation.
4. SqlDataSource requires complete connection string to connect with database. ObjectDataSource exposes TypeName attribute that is a name of middle layer class may used to perform database related operations. Data access class must be placed in App_Code directory.
5. Caching is same for both controls but ObjectDataSource control fires NotSupported exception if return type of SelectMethod is other than DataSet.
Thursday, March 30, 2006
How to: Get list of table names from MS Access Database in ASP.NET 2.0
Dim sConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\sample.mdb"
Dim olecon As New OleDbConnection(sConn)
olecon.Open()
Dim tblrestrictions As String() = New String() {Nothing, Nothing, Nothing, "TABLE"}
Dim dt As DataTable = olecon.GetSchema("tables", tblrestrictions)
olecon.Close()
GridView1.DataSource = dt
GridView1.DataBind()
Restrictions are a string array in the following format:
{TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME, TABLE_TYPE}.
Using ADOX and Msysobjects works fine with windows applications but may problematic for web apps[permission related problems]. If you use Msysobjects directly in query, following error will be displayed:
Record(s) cannot be read; no read permission on 'MSysObjects'
So it's better to use GetSchema with restriction.
How To - ExecuteScalar ()
Executes the query, and returns the first column of the first row in the resultset returned by the query. Extra columns or rows are ignored.
ExecuteScalar is a fast way to fetch one value.
Results:
If ExecuteScalar return 0 (zero) means no similar record found in database (According to condition is defined in WHERE clause).
Code Snippets:
Snippet 1:
Scenario: Avoid entry of duplicate user names by using ExecuteScalar method.
DBConnection.Open()
SQLString = "SELECT Count(*) FROM tblLogin " & _
WHERE username = '" & txtUserName.Text & "'"
DBCommand = New OleDbCommand(SQLString, DBConnection)
If DBCommand.ExecuteScalar() <> 0 Then
lblError.Text = "Sorry. User Name Already Present."
End If
DBConnection.Close()
Snippet 2:
Scenario: Check whether User Name and Password is present in database by using ExecuteScalar method.
DBConnection.Open()
SQLString = "SELECT Count(*) FROM tblLogin " & _
WHERE username = '" & txtUserName.Text & "' AND Password='" & txtPassword.Text & "'"
DBCommand = New OleDbCommand(SQLString, DBConnection)
If DBCommand.ExecuteScalar() <> 0 Then
'IF condition satisfied means User Name and Password is correct.
' write code below here.
End If
DBConnection.Close()
Conclusion:
Use to get result of Queries like count, min, max...
Friday, March 24, 2006
Solution: AccessDataSource control generates error for autoincrement data type field while Inserting a record.
"You tried to assign the Null value to a variable that is not a Variant data type. "
Solution:
When you use AccessDataSource control to insert a record in database. If one of field type is autoincrement then above error will shoot on the screen.
Normally you remove autoincrement data type fields from InsertCommand. This creates another problem. You don't face any error, but data is not saved in respective fields in database.
So here is a solution.
First, remove autoincrement field from InsertCommand.
Second, Important step, remove autoincrement field line from InsertParameters section of AccessDataSource control.