Calling Web Services with ASP.NET AJAX
http://www.asp.net/ajax/tutorials
2010年7月28日星期三
2010年7月27日星期二
Using jQuery in ASP.Net AJAX Applications
http://www.codedigest.com/Articles/ASPNETAJAX/183_Using_JQuery_in_ASPNet_AJAX_Applications_%e2%80%93_Part_1.aspx
we implemented the server side functionality using a separate aspx page and it is called through the AJAX methods available in JQuery.
We made AJAX calls through POST and GET method using JQuery library.
http://www.codedigest.com/Articles/ASPNETAJAX/185_Using_JQuery_in_ASPNet_AJAX_Applications%E2%80%93Part_2.aspx
Server side functionality can be very well implemented through a mere server side function instead of a separate page.
To implement the requirement through PageMethods, we need to define a function in codebehind and decorate it with an attribute called WebMethod. To call this PageMethods from JavaScript, we need to enable the EnablePageMethods property of ScriptManager to true. This will create a JavaScript proxy for all the page methods declared in the page and it will be injected to the client side. We can use JQuery.ajax() method to call the PageMethod from client side.
we implemented the server side functionality using a separate aspx page and it is called through the AJAX methods available in JQuery.
We made AJAX calls through POST and GET method using JQuery library.
http://www.codedigest.com/Articles/ASPNETAJAX/185_Using_JQuery_in_ASPNet_AJAX_Applications%E2%80%93Part_2.aspx
Server side functionality can be very well implemented through a mere server side function instead of a separate page.
To implement the requirement through PageMethods, we need to define a function in codebehind and decorate it with an attribute called WebMethod. To call this PageMethods from JavaScript, we need to enable the EnablePageMethods property of ScriptManager to true. This will create a JavaScript proxy for all the page methods declared in the page and it will be injected to the client side. We can use JQuery.ajax() method to call the PageMethod from client side.
2010年7月23日星期五
Security
Cross Site Scripting
http://www.owasp.org/index.php/Top_10_2007-Cross_Site_Scripting
How To: Prevent Cross-Site Scripting in ASP.NET
http://msdn.microsoft.com/en-us/library/ff649310.aspx
The two most important countermeasures to prevent cross-site scripting attacks are to:
•Constrain input.
•Encode output.
Security Design Principles - Input/Data Validation
http://www.guidanceshare.com/wiki/Security_Design_Principles_-_Input/Data_Validation
http://www.owasp.org/index.php/Top_10_2007-Cross_Site_Scripting
How To: Prevent Cross-Site Scripting in ASP.NET
http://msdn.microsoft.com/en-us/library/ff649310.aspx
The two most important countermeasures to prevent cross-site scripting attacks are to:
•Constrain input.
•Encode output.
Security Design Principles - Input/Data Validation
http://www.guidanceshare.com/wiki/Security_Design_Principles_-_Input/Data_Validation
TRY...CATCH in SQL Server 2005
http://www.4guysfromrolla.com/webtech/041906-1.shtml
because the @@ERROR variable is set after every SQL statement. Therefore, if the first DELETE statement has an error the @@ERROR variable will be set to its error number. Then, the second DELETE will execute. If this second DELETE succeeds, @@ERROR will be set back to 0, in which case the transaction will be committed even though there was a problem with the first statement! Whoops!
The SQL Server 2005 TRY...CATCH block executes a number of statements in the TRY block. If there are no errors in any of the statements, control proceeds to after the CATCH block. If, however, one of the statements causes an error, control branches immediately to the start of the CATCH block.
CREATE PROCEDURE DeleteEmployee ( @EmployeeID int )
AS
BEGIN TRY
BEGIN TRANSACTION -- Start the transaction
-- Delete the Employee's phone numbers
DELETE FROM EmployeePhoneNumbers
WHERE EmployeeID = @EmployeeID
-- Delete the Employee record
DELETE FROM Employees
WHERE EmployeeID = @EmployeeID
-- If we reach here, success!
COMMIT
END TRY
BEGIN CATCH
-- Whoops, there was an error
IF @@TRANCOUNT > 0
ROLLBACK
-- Raise an error with the details of the exception
DECLARE @ErrMsg nvarchar(4000), @ErrSeverity int
SELECT @ErrMsg = ERROR_MESSAGE(),
@ErrSeverity = ERROR_SEVERITY()
RAISERROR(@ErrMsg, @ErrSeverity, 1)
END CATCH
because the @@ERROR variable is set after every SQL statement. Therefore, if the first DELETE statement has an error the @@ERROR variable will be set to its error number. Then, the second DELETE will execute. If this second DELETE succeeds, @@ERROR will be set back to 0, in which case the transaction will be committed even though there was a problem with the first statement! Whoops!
The SQL Server 2005 TRY...CATCH block executes a number of statements in the TRY block. If there are no errors in any of the statements, control proceeds to after the CATCH block. If, however, one of the statements causes an error, control branches immediately to the start of the CATCH block.
CREATE PROCEDURE DeleteEmployee ( @EmployeeID int )
AS
BEGIN TRY
BEGIN TRANSACTION -- Start the transaction
-- Delete the Employee's phone numbers
DELETE FROM EmployeePhoneNumbers
WHERE EmployeeID = @EmployeeID
-- Delete the Employee record
DELETE FROM Employees
WHERE EmployeeID = @EmployeeID
-- If we reach here, success!
COMMIT
END TRY
BEGIN CATCH
-- Whoops, there was an error
IF @@TRANCOUNT > 0
ROLLBACK
-- Raise an error with the details of the exception
DECLARE @ErrMsg nvarchar(4000), @ErrSeverity int
SELECT @ErrMsg = ERROR_MESSAGE(),
@ErrSeverity = ERROR_SEVERITY()
RAISERROR(@ErrMsg, @ErrSeverity, 1)
END CATCH
2010年7月22日星期四
channel9
channel9 Videos
http://channel9.msdn.com/Media/Videos/#Page=1
channel9 Course
http://channel9.msdn.com/learn/courses/
http://channel9.msdn.com/Media/Videos/#Page=1
channel9 Course
http://channel9.msdn.com/learn/courses/
SQL Server stuffs
SQL 2008 Series: Triggers
http://www.youtube.com/watch?v=URs_rnzkmxs&feature=related
Trigger in SQL Server 2005 tutorial from wingslive.com
http://www.youtube.com/watch?v=5zyQIt-8NRQ&feature=related
SQL 2008 Series: Views
http://www.youtube.com/watch?v=to_0_bODY2Y&feature=channel
SQL Server 2008 T-SQL Debugger
http://www.youtube.com/watch?v=618LE_FZCxI&feature=related
Microsoft SQL Server 2005: Execution Plans
http://www.youtube.com/watch?v=uGi7_LkJXFI&feature=related
Using Statistics to Improve Query Performance
http://msdn.microsoft.com/en-us/library/ms190397.aspx
DBCC SHOW_STATISTICS (Transact-SQL)
http://msdn.microsoft.com/en-us/library/ms174384.aspx
Performance Tuning in SQL Server (GOOD)
http://www.youtube.com/watch?v=P97_oFfD218&NR=1
DBCC DROPCLEANBUFFERS
DBCC FREEPROCCACHE
SET STATISTICS IO ON
SET STATISTICS TIME ON
1. Limit the number of columns returned
2. Create primary key on table
3. Create an Index on the columns in the WHERE clause
4. Limit the number of rows by using TOP
5. When working with joins, have an index on the columns in the JOIN and where clause
6. If you use multiple columns in WHERE or ORDER BY, create compound index, pay attention to the order of index
7. If you are trying to get unique values, use GROUP BY instead of DISTINCT
SQL Server 2008 Query Optimization - Part IV
http://www.youtube.com/watch?v=QFyJ2NtebzM&feature=channel
8. Use EXISTS instead of IN clause for sub queries
9. Use SET NOCOUNT OFF
Database Management Tool - SQL Server Profiler
http://www.youtube.com/watch?v=1RLuHzkyQy4
SQL Joins, nested loops and all that in less than 6 minutes
http://www.youtube.com/watch?v=SmDZaH855qE&feature=related
Rewriting SQL queries for Performance in 9 minutes (GOOD)
http://www.youtube.com/watch?v=ZVisY-fEoMw&feature=related
1. Try to remove the rows that not be able to seen in the final result set ASAP
2. group and sort as little column as possible
3. Join late
Query Tuning
http://msdn.microsoft.com/en-us/library/ms176005.aspx
General Index Design Guidelines
http://msdn.microsoft.com/en-us/library/ms191195.aspx
SET ANSI_NULLS { ON | OFF }
When SET ANSI_NULLS is ON, a SELECT statement that uses WHERE column_name = NULL returns zero rows even if there are null values in column_name. A SELECT statement that uses WHERE column_name <> NULL returns zero rows even if there are nonnull values in column_name.
SET QUOTED_IDENTIFIER { ON | OFF }
When SET QUOTED_IDENTIFIER is ON (default), identifiers can be delimited by double quotation marks, and literals must be delimited by single quotation marks. When SET QUOTED_IDENTIFIER is OFF, identifiers cannot be quoted and must follow all Transact-SQL rules for identifiers.
http://www.youtube.com/watch?v=URs_rnzkmxs&feature=related
Trigger in SQL Server 2005 tutorial from wingslive.com
http://www.youtube.com/watch?v=5zyQIt-8NRQ&feature=related
SQL 2008 Series: Views
http://www.youtube.com/watch?v=to_0_bODY2Y&feature=channel
SQL Server 2008 T-SQL Debugger
http://www.youtube.com/watch?v=618LE_FZCxI&feature=related
Microsoft SQL Server 2005: Execution Plans
http://www.youtube.com/watch?v=uGi7_LkJXFI&feature=related
Using Statistics to Improve Query Performance
http://msdn.microsoft.com/en-us/library/ms190397.aspx
DBCC SHOW_STATISTICS (Transact-SQL)
http://msdn.microsoft.com/en-us/library/ms174384.aspx
Performance Tuning in SQL Server (GOOD)
http://www.youtube.com/watch?v=P97_oFfD218&NR=1
DBCC DROPCLEANBUFFERS
DBCC FREEPROCCACHE
SET STATISTICS IO ON
SET STATISTICS TIME ON
1. Limit the number of columns returned
2. Create primary key on table
3. Create an Index on the columns in the WHERE clause
4. Limit the number of rows by using TOP
5. When working with joins, have an index on the columns in the JOIN and where clause
6. If you use multiple columns in WHERE or ORDER BY, create compound index, pay attention to the order of index
7. If you are trying to get unique values, use GROUP BY instead of DISTINCT
SQL Server 2008 Query Optimization - Part IV
http://www.youtube.com/watch?v=QFyJ2NtebzM&feature=channel
8. Use EXISTS instead of IN clause for sub queries
9. Use SET NOCOUNT OFF
Database Management Tool - SQL Server Profiler
http://www.youtube.com/watch?v=1RLuHzkyQy4
SQL Joins, nested loops and all that in less than 6 minutes
http://www.youtube.com/watch?v=SmDZaH855qE&feature=related
Rewriting SQL queries for Performance in 9 minutes (GOOD)
http://www.youtube.com/watch?v=ZVisY-fEoMw&feature=related
1. Try to remove the rows that not be able to seen in the final result set ASAP
2. group and sort as little column as possible
3. Join late
Query Tuning
http://msdn.microsoft.com/en-us/library/ms176005.aspx
General Index Design Guidelines
http://msdn.microsoft.com/en-us/library/ms191195.aspx
SET ANSI_NULLS { ON | OFF }
When SET ANSI_NULLS is ON, a SELECT statement that uses WHERE column_name = NULL returns zero rows even if there are null values in column_name. A SELECT statement that uses WHERE column_name <> NULL returns zero rows even if there are nonnull values in column_name.
SET QUOTED_IDENTIFIER { ON | OFF }
When SET QUOTED_IDENTIFIER is ON (default), identifiers can be delimited by double quotation marks, and literals must be delimited by single quotation marks. When SET QUOTED_IDENTIFIER is OFF, identifiers cannot be quoted and must follow all Transact-SQL rules for identifiers.
Logic Data Modeling
1 - Introduction
http://www.youtube.com/watch?v=IiVq8M5DBkk&feature=channel
2 - Candidate Key
http://www.youtube.com/watch?v=BGMwuOtRfqU&feature=channel
3 - Normalization
http://www.youtube.com/watch?v=ZiB-BKCzS_I&feature=channel
4 - Normalization Example
http://www.youtube.com/watch?v=pJ47btpjAhA&feature=channel
5 - 1st Normal Form
http://www.youtube.com/watch?v=q3Wg2fZENK0&feature=channel
6 - Process & Data: Data Flow Diagram
http://www.youtube.com/watch?v=X9MyqHGPDaI&feature=related
7 - 3rd Normal Form
http://www.youtube.com/watch?v=HH-QR7t-kMo&feature=related
8 - Entity Relationship Diagram, part 1
http://www.youtube.com/watch?v=q1GaaGHHAqM&feature=related
9 - Entity Relationship Diagram, part 2
http://www.youtube.com/watch?v=lXAGQ8vmhCY&feature=related
http://www.youtube.com/watch?v=IiVq8M5DBkk&feature=channel
2 - Candidate Key
http://www.youtube.com/watch?v=BGMwuOtRfqU&feature=channel
3 - Normalization
http://www.youtube.com/watch?v=ZiB-BKCzS_I&feature=channel
4 - Normalization Example
http://www.youtube.com/watch?v=pJ47btpjAhA&feature=channel
5 - 1st Normal Form
http://www.youtube.com/watch?v=q3Wg2fZENK0&feature=channel
6 - Process & Data: Data Flow Diagram
http://www.youtube.com/watch?v=X9MyqHGPDaI&feature=related
7 - 3rd Normal Form
http://www.youtube.com/watch?v=HH-QR7t-kMo&feature=related
8 - Entity Relationship Diagram, part 1
http://www.youtube.com/watch?v=q1GaaGHHAqM&feature=related
9 - Entity Relationship Diagram, part 2
http://www.youtube.com/watch?v=lXAGQ8vmhCY&feature=related
Entity Data Model
ADO.NET Tech Preview: Entity Data Model
http://msdn.microsoft.com/en-us/library/aa697428(VS.80).aspx
http://msdn.microsoft.com/en-us/library/aa697428(VS.80).aspx
Entity Framework
The Entity Framework vs. The Data Access Layer (Part 0: Introduction)
http://blogs.objectsharp.com/cs/blogs/barry/archive/2008/04/27/the-entity-framework-vs-the-data-access-layer-part-0-introduction.aspx
The Entity Framework vs. The Data Access Layer (Part 1: The EF as a DAL)
http://blogs.objectsharp.com/cs/blogs/barry/archive/2008/05/06/the-entity-framework-vs-the-data-access-layer-part-1-the-ef-as-a-dal.aspx
ADO.NET Entity Framework .Net 4.0
http://msdn.microsoft.com/en-us/library/bb399572.aspx
Get Started with the Entity Framework
http://www.asp.net/aspnet-35/videos/how-do-i-get-started-with-the-entity-framework
Use the New Entity Data Source
http://www.asp.net/aspnet-35/videos/how-do-i-use-the-new-entity-data-source
http://blogs.objectsharp.com/cs/blogs/barry/archive/2008/04/27/the-entity-framework-vs-the-data-access-layer-part-0-introduction.aspx
The Entity Framework vs. The Data Access Layer (Part 1: The EF as a DAL)
http://blogs.objectsharp.com/cs/blogs/barry/archive/2008/05/06/the-entity-framework-vs-the-data-access-layer-part-1-the-ef-as-a-dal.aspx
ADO.NET Entity Framework .Net 4.0
http://msdn.microsoft.com/en-us/library/bb399572.aspx
Get Started with the Entity Framework
http://www.asp.net/aspnet-35/videos/how-do-i-get-started-with-the-entity-framework
Use the New Entity Data Source
http://www.asp.net/aspnet-35/videos/how-do-i-use-the-new-entity-data-source
Windows Communication Foundation
Windows Communication Foundation
.Net 3.5 http://msdn.microsoft.com/en-us/library/ms735119.aspx
.Net 4.0 http://msdn.microsoft.com/en-us/library/dd456779.aspx
Getting Started Tutorial
http://msdn.microsoft.com/en-us/library/ms734712.aspx
What Is Windows Communication Foundation
http://msdn.microsoft.com/en-us/library/ms731082.aspx
WCF Samples
http://msdn.microsoft.com/en-us/library/ms730936.aspx
.Net 3.5 http://msdn.microsoft.com/en-us/library/ms735119.aspx
.Net 4.0 http://msdn.microsoft.com/en-us/library/dd456779.aspx
Getting Started Tutorial
http://msdn.microsoft.com/en-us/library/ms734712.aspx
What Is Windows Communication Foundation
http://msdn.microsoft.com/en-us/library/ms731082.aspx
WCF Samples
http://msdn.microsoft.com/en-us/library/ms730936.aspx
2010年7月20日星期二
System Exception & Application Exception
You can find them in Visual Studio, Debug -> Exceptions...
System.Data.SqlClient.SqlException
System.IO.IOException
System.ArgumentException
System.NullReferenceException
System.OutOfMemoryException
System.OverflowException
System.DivideByZeroExecption
...
Two categories of exceptions exist under the base class Exception:
•The pre-defined common language runtime exception classes derived from SystemException.
•The user-defined application exception classes derived from ApplicationException.
User applications, not the common language runtime, throw custom exceptions derived from the ApplicationException class. The ApplicationException class differentiates between exceptions defined by applications versus exceptions defined by the system.
If you are designing an application that needs to create its own exceptions, you are advised to derive custom exceptions from the Exception class. It was originally thought that custom exceptions should derive from the ApplicationException class; however in practice this has not been found to add significant value. For more information, see Best Practices for Handling Exceptions http://msdn.microsoft.com/en-us/library/seyhszts.aspx.
If the event is truly exceptional and is an error (such as an unexpected end-of-file), using exception handling is better because less code is executed in the normal case. If the event happens routinely, using the programmatic method to check for errors is better. In this case, if an exception occurs, the exception will take longer to handle.
System.Data.SqlClient.SqlException
System.IO.IOException
System.ArgumentException
System.NullReferenceException
System.OutOfMemoryException
System.OverflowException
System.DivideByZeroExecption
...
Two categories of exceptions exist under the base class Exception:
•The pre-defined common language runtime exception classes derived from SystemException.
•The user-defined application exception classes derived from ApplicationException.
User applications, not the common language runtime, throw custom exceptions derived from the ApplicationException class. The ApplicationException class differentiates between exceptions defined by applications versus exceptions defined by the system.
If you are designing an application that needs to create its own exceptions, you are advised to derive custom exceptions from the Exception class. It was originally thought that custom exceptions should derive from the ApplicationException class; however in practice this has not been found to add significant value. For more information, see Best Practices for Handling Exceptions http://msdn.microsoft.com/en-us/library/seyhszts.aspx.
If the event is truly exceptional and is an error (such as an unexpected end-of-file), using exception handling is better because less code is executed in the normal case. If the event happens routinely, using the programmatic method to check for errors is better. In this case, if an exception occurs, the exception will take longer to handle.
Linq to SQL
Linq to SQL
Stored Procedures using LINQ to SQL Classes
http://www.youtube.com/watch?v=t8rbLhnR8B4
Visual Studio 2008, Linq to SQL, C#, and WPF
Tutorial 1
http://www.youtube.com/watch?v=LEWZO4fO3hQ&feature=related
Tutorial 2
http://www.youtube.com/watch?v=d5B4cJ4yhB4
Tutorial 3
http://www.youtube.com/watch?v=BKrCrsfMn1c&feature=related
Tutorial 4 script for create table, constraints
http://www.youtube.com/watch?v=EyqeXsw-VGg
Tutorial 5
http://www.youtube.com/watch?v=E7abstYQxFk&feature=related
Tutorial 6 WPF user interface
http://www.youtube.com/watch?v=k4qOeVKf6g8
Tutorial 7 Add top menus
http://www.youtube.com/watch?v=2YvKrpycGxg&feature=related
Tutorial 8 Add sub menus
http://www.youtube.com/watch?v=K3grl_4ex-4&feature=related
Tutorial 9 Add Linq to SQL class
http://www.youtube.com/watch?v=IN01AvdEoig
Tutorial 10 Add other WPF windows
http://www.youtube.com/watch?v=G_fHht6J6xc&feature=related
Tutorial 11 ViewStudent GridView
http://www.youtube.com/watch?v=RBoZXO4FwKk&feature=related
Tutorial 12 Open ViewStudent window, exit main window
http://www.youtube.com/watch?v=mCbEhRJWWQ0&feature=related
Tutorial 13 Add student window
http://www.youtube.com/watch?v=RJoVNg7FIww&feature=related
Tutorial 14
http://www.youtube.com/watch?v=E_IZ6J7tML0&feature=related
Tutorial 15 Add validation
http://www.youtube.com/watch?v=4JyIBZ4JWME&feature=related
Tutorial 16 AddStudent method
http://www.youtube.com/watch?v=SyuXqdCDMiQ&feature=related
Tutorial 17
http://www.youtube.com/watch?v=fa_KOxs47yo&feature=related
Tutorial 18 Update student
http://www.youtube.com/watch?v=84l56lw-0R8&feature=related
Tutorial 19
http://www.youtube.com/watch?v=YiryqqN_ylw&feature=related
Tutorial 20 Update student method
http://www.youtube.com/watch?v=EVXD2x_Ia1o&feature=related
Tutorial 21 Delete student
http://www.youtube.com/watch?v=4snI4VerhqQ&feature=related
Stored Procedures using LINQ to SQL Classes
http://www.youtube.com/watch?v=t8rbLhnR8B4
Visual Studio 2008, Linq to SQL, C#, and WPF
Tutorial 1
http://www.youtube.com/watch?v=LEWZO4fO3hQ&feature=related
Tutorial 2
http://www.youtube.com/watch?v=d5B4cJ4yhB4
Tutorial 3
http://www.youtube.com/watch?v=BKrCrsfMn1c&feature=related
Tutorial 4 script for create table, constraints
http://www.youtube.com/watch?v=EyqeXsw-VGg
Tutorial 5
http://www.youtube.com/watch?v=E7abstYQxFk&feature=related
Tutorial 6 WPF user interface
http://www.youtube.com/watch?v=k4qOeVKf6g8
Tutorial 7 Add top menus
http://www.youtube.com/watch?v=2YvKrpycGxg&feature=related
Tutorial 8 Add sub menus
http://www.youtube.com/watch?v=K3grl_4ex-4&feature=related
Tutorial 9 Add Linq to SQL class
http://www.youtube.com/watch?v=IN01AvdEoig
Tutorial 10 Add other WPF windows
http://www.youtube.com/watch?v=G_fHht6J6xc&feature=related
Tutorial 11 ViewStudent GridView
http://www.youtube.com/watch?v=RBoZXO4FwKk&feature=related
Tutorial 12 Open ViewStudent window, exit main window
http://www.youtube.com/watch?v=mCbEhRJWWQ0&feature=related
Tutorial 13 Add student window
http://www.youtube.com/watch?v=RJoVNg7FIww&feature=related
Tutorial 14
http://www.youtube.com/watch?v=E_IZ6J7tML0&feature=related
Tutorial 15 Add validation
http://www.youtube.com/watch?v=4JyIBZ4JWME&feature=related
Tutorial 16 AddStudent method
http://www.youtube.com/watch?v=SyuXqdCDMiQ&feature=related
Tutorial 17
http://www.youtube.com/watch?v=fa_KOxs47yo&feature=related
Tutorial 18 Update student
http://www.youtube.com/watch?v=84l56lw-0R8&feature=related
Tutorial 19
http://www.youtube.com/watch?v=YiryqqN_ylw&feature=related
Tutorial 20 Update student method
http://www.youtube.com/watch?v=EVXD2x_Ia1o&feature=related
Tutorial 21 Delete student
http://www.youtube.com/watch?v=4snI4VerhqQ&feature=related
2010年7月19日星期一
Automating Visual Studio 2008
http://www.geekzone.co.nz/vs2008/6324
Efficient Navigation:
Visual Studio’s Code Editor provides efficient means to navigate around large files (using collapsible code blocks), large projects (using Bookmarks) that contain large numbers of classes and/or properties (using Object Explorer) as well as solutions that contain numerous projects (using Solution Explorer).
Code Creation:
In addition to UI designers, Visual Studio provider database schema designers (to graphically create and design database schemas as well as queries), a class designer (to graphically develop or document classes and their interactions), and a mapping designer (to graphically design the mapping between database schemas and the code entities that encapsulate the data).
Code Refactoring:
Beginning with VS2005, several refactoring tools are built directly into the IDE, which are accessible from the Code Editor’s context menu, or the main menu’s Refactor menu (which is only visible when the Code Editor has focus).
The refactoring tools offered are sparse, but helpful:
o Extract Method: Defines a new method, based on a selection of code statements.
o Encapsulate Field: Turns a public field into a private field, wrapping it with a public property.
o Extract Interface: Defines a new interface based on the current class’ public properties and methods.
o Reorder Parameters: Provides a way to reorder member parameters, as well as the arguments of all references to it throughout a project.
o Remove Parameters: Removes a member’s parameter, and the argument from of all references to it throughout a project.
o Rename: This allows you to rename a code token (method, field, etc.), and all references to it throughout a project.
o Promote Local Variable to Parameter: Moves a local variable to the parameter set of the defining method.
Efficient Navigation:
Visual Studio’s Code Editor provides efficient means to navigate around large files (using collapsible code blocks), large projects (using Bookmarks) that contain large numbers of classes and/or properties (using Object Explorer) as well as solutions that contain numerous projects (using Solution Explorer).
Code Creation:
In addition to UI designers, Visual Studio provider database schema designers (to graphically create and design database schemas as well as queries), a class designer (to graphically develop or document classes and their interactions), and a mapping designer (to graphically design the mapping between database schemas and the code entities that encapsulate the data).
Code Refactoring:
Beginning with VS2005, several refactoring tools are built directly into the IDE, which are accessible from the Code Editor’s context menu, or the main menu’s Refactor menu (which is only visible when the Code Editor has focus).
The refactoring tools offered are sparse, but helpful:
o Extract Method: Defines a new method, based on a selection of code statements.
o Encapsulate Field: Turns a public field into a private field, wrapping it with a public property.
o Extract Interface: Defines a new interface based on the current class’ public properties and methods.
o Reorder Parameters: Provides a way to reorder member parameters, as well as the arguments of all references to it throughout a project.
o Remove Parameters: Removes a member’s parameter, and the argument from of all references to it throughout a project.
o Rename: This allows you to rename a code token (method, field, etc.), and all references to it throughout a project.
o Promote Local Variable to Parameter: Moves a local variable to the parameter set of the defining method.
How to debug in Visual Studio
JavaScript Debugging in Visual Studio 2008
http://www.asp.net/aspnet-35/videos/javascript-debugging-in-visual-studio-2008
How Do I: Learn Tips and Tricks for Debugging in Visual Studio?
http://www.youtube.com/watch?v=4uyDBM-qTkk&feature=related
Visual Studio Debugging Tutorial
http://dotnetperls.com/debugging-1
It has many more options, including Call Stack, Command Window, Exceptions, and Autos. You can configure breakpoints to simply write messages to the console, or to keep counts of how many times they are hit. This is great for performance testing.
Here we note that the .NET Framework provides a variety of useful methods in the Debug class that can be used to hard-code debugging facilities in your programs. Some methods that you can use are Debug.Write and Debug.Assert. The benefit to these methods over the Console methods is that they are removed in Release builds of your application. You can find more details on these methods.
How to trace and debug in Visual C#
http://support.microsoft.com/kb/815788
You can also use the Trace class to produce messages that monitor the execution of an application. The Trace and Debug classes share most of the same methods to produce output, including the following:
WriteLine
WriteLineIf
Indent
Unindent
Assert
Flush
a Release Solution Configuration project only generates output from a Trace class. The Release Solution Configuration project ignores any Debug class method invocations.
To display the content of selected variables, use the Debug.WriteLine method.
Use the Assert method of the Debug class so that the Output window displays the message only if a specified condition evaluates to false.
Basic Debugging Features In Visual Studio 2005
http://odetocode.com/Articles/425.aspx
Another way to halt execution of a program is to ask the debugger to break when an exception occurs. By default, the debugger will only break if the exception goes unhandled, but this behavior is configurable. Select Exceptions from the Debug menu and you’ll see a tree display of all possible exceptions alongside checkboxes to indicate if the debugger should break when an exception “is thrown”, or only break if the exception is “user-unhandled”.
Breaking on exceptions can be useful when you are trying to track down an exception that occurs, but have not determined under what condition the exception occurs, or where the exception occurs.
DataTips are a transient display of information – once your mouse leaves the DataTip area the DataTip display will disappear.
A Watch Window will display an object’s state until you explicitly remove the object from the window.
The locals window will automatically display all local variables in the current block of code. If you are inside of a method, the locals window will display the method parameters and locally defined variables.
The Autos window (Debug -> Windows -> Autos) will display variables and expressions from the current line of code, and the preceding line of code.
A visualizer is a new way to view data in Visual Studio 2005. Some dataypes are too complex to display in a DataTip or watch window. For example, a DataSet is a tremendously complex and hierarchical object. Trying to drill into the 5th column of the 10th row of the 2nd table of a DataSet is cumbersome. Fortunately, a Visualizer exists for DataSet objects that will display the data in a more natural environment, namely an editable data grid.
Whenever a magnifying glass appears in a DataTip or watch window there is a visualizer available for the object. Double click on the magnifying glass to use the default visualizer. If multiple visualizers are available, you can click on the drop down chevron next to the magnifying glass and select which visualizer you’d like to use. For instance, a string will have three visualizers available: a text visualizer, an HTML visualizer, and an XML visualizer. There is also a visualizer for the DataSet and DataTable classes.
Improved Debugging with Visual Studio 2005's Debugger Visualizers
http://aspnet.4guysfromrolla.com/articles/011806-1.aspx
Visual Studio 2005 ships with four visualizers, a DataSet visualizer, which shows the contents of a DataSet in a grid, and three text-based visualizers: one for text, one for XML, and one for HTML. The screenshot below shows the XML Visualizer in action, which provides a much more readable view of the XML than simply squishing it all on one line.
Immediate and Command window in Visual Studio
http://dotnetdud.wordpress.com/2007/12/25/immediate-and-command-window-in-visual-studio/
The Command window is used to execute commands or aliases directly in the Visual Studio integrated development environment (IDE). You can execute both menu commands and commands that do not appear on any menu. To display the Command window, choose Other Windows from the View menu, and select Command Window
The Immediate window is used to debug and evaluate expressions, execute statements, print variable values, and so forth. It allows you to enter expressions to be evaluated or executed by the development language during debugging. To display the Immediate window, open a project for editing, then choose Windows from the Debug menu and select Immediate.
It also includes a seemingly very complete list of commands and aliases that you can execute (for VS 2005 at least) - from either window, as far as I understand. Once of the nice features is that you can switch between the two windows simply by executing the cmd and immed commands.
In addition, see also the MSDN pages on the Command Window and the Immediate Window.
http://www.asp.net/aspnet-35/videos/javascript-debugging-in-visual-studio-2008
How Do I: Learn Tips and Tricks for Debugging in Visual Studio?
http://www.youtube.com/watch?v=4uyDBM-qTkk&feature=related
Visual Studio Debugging Tutorial
http://dotnetperls.com/debugging-1
It has many more options, including Call Stack, Command Window, Exceptions, and Autos. You can configure breakpoints to simply write messages to the console, or to keep counts of how many times they are hit. This is great for performance testing.
Here we note that the .NET Framework provides a variety of useful methods in the Debug class that can be used to hard-code debugging facilities in your programs. Some methods that you can use are Debug.Write and Debug.Assert. The benefit to these methods over the Console methods is that they are removed in Release builds of your application. You can find more details on these methods.
How to trace and debug in Visual C#
http://support.microsoft.com/kb/815788
You can also use the Trace class to produce messages that monitor the execution of an application. The Trace and Debug classes share most of the same methods to produce output, including the following:
WriteLine
WriteLineIf
Indent
Unindent
Assert
Flush
a Release Solution Configuration project only generates output from a Trace class. The Release Solution Configuration project ignores any Debug class method invocations.
To display the content of selected variables, use the Debug.WriteLine method.
Use the Assert method of the Debug class so that the Output window displays the message only if a specified condition evaluates to false.
Basic Debugging Features In Visual Studio 2005
http://odetocode.com/Articles/425.aspx
Another way to halt execution of a program is to ask the debugger to break when an exception occurs. By default, the debugger will only break if the exception goes unhandled, but this behavior is configurable. Select Exceptions from the Debug menu and you’ll see a tree display of all possible exceptions alongside checkboxes to indicate if the debugger should break when an exception “is thrown”, or only break if the exception is “user-unhandled”.
Breaking on exceptions can be useful when you are trying to track down an exception that occurs, but have not determined under what condition the exception occurs, or where the exception occurs.
DataTips are a transient display of information – once your mouse leaves the DataTip area the DataTip display will disappear.
A Watch Window will display an object’s state until you explicitly remove the object from the window.
The locals window will automatically display all local variables in the current block of code. If you are inside of a method, the locals window will display the method parameters and locally defined variables.
The Autos window (Debug -> Windows -> Autos) will display variables and expressions from the current line of code, and the preceding line of code.
A visualizer is a new way to view data in Visual Studio 2005. Some dataypes are too complex to display in a DataTip or watch window. For example, a DataSet is a tremendously complex and hierarchical object. Trying to drill into the 5th column of the 10th row of the 2nd table of a DataSet is cumbersome. Fortunately, a Visualizer exists for DataSet objects that will display the data in a more natural environment, namely an editable data grid.
Whenever a magnifying glass appears in a DataTip or watch window there is a visualizer available for the object. Double click on the magnifying glass to use the default visualizer. If multiple visualizers are available, you can click on the drop down chevron next to the magnifying glass and select which visualizer you’d like to use. For instance, a string will have three visualizers available: a text visualizer, an HTML visualizer, and an XML visualizer. There is also a visualizer for the DataSet and DataTable classes.
Improved Debugging with Visual Studio 2005's Debugger Visualizers
http://aspnet.4guysfromrolla.com/articles/011806-1.aspx
Visual Studio 2005 ships with four visualizers, a DataSet visualizer, which shows the contents of a DataSet in a grid, and three text-based visualizers: one for text, one for XML, and one for HTML. The screenshot below shows the XML Visualizer in action, which provides a much more readable view of the XML than simply squishing it all on one line.
Immediate and Command window in Visual Studio
http://dotnetdud.wordpress.com/2007/12/25/immediate-and-command-window-in-visual-studio/
The Command window is used to execute commands or aliases directly in the Visual Studio integrated development environment (IDE). You can execute both menu commands and commands that do not appear on any menu. To display the Command window, choose Other Windows from the View menu, and select Command Window
The Immediate window is used to debug and evaluate expressions, execute statements, print variable values, and so forth. It allows you to enter expressions to be evaluated or executed by the development language during debugging. To display the Immediate window, open a project for editing, then choose Windows from the Debug menu and select Immediate.
It also includes a seemingly very complete list of commands and aliases that you can execute (for VS 2005 at least) - from either window, as far as I understand. Once of the nice features is that you can switch between the two windows simply by executing the cmd and immed commands.
In addition, see also the MSDN pages on the Command Window and the Immediate Window.
TDD & Unit Test
TDD Tests are not Unit Tests
http://stephenwalther.com/blog/archive/2009/04/11/tdd-tests-are-not-unit-tests.aspx
Unit testing with Visual Studio 2008
http://www.geekzone.co.nz/vs2008/4819
A Unit Testing Walkthrough with Visual Studio Team Test
http://msdn.microsoft.com/en-us/library/ms379625(VS.80).aspx
The first noteworthy characteristic of Listing 6 is the addition of the DataSourceAttribute in which the connection string, table name, and access order are specified. In this listing we use a database file name to identify the database. The advantage of this is that the file will travel with the test project, assuming it is updated to be a relative path.
The second important characteristic is the TestContext.DataRow calls. TestContext is a property that the generator provided when we ran the Create Tests wizard. The property is automatically assigned by the test execution engine at runtime so that within a test we can access data associated with the test context, As Figure 7 shows, the TestContext provides data such as the TestDirectory and TestName, along with methods such as BeginTimer() and EndTimer(). What is most significant for the ChangePasswordTest() method is the DataRow property. Because the ChangePasswordTest() method is decorated with DataSourceAttribute, it will be called once for each record returned from the table specified by the attribute. This enables the test code to use the data within an executing test and have the test repeat for each record inserted into the LogonInfoTest table. If the table contains four records, then the test will be executed four separate times.
http://stephenwalther.com/blog/archive/2009/04/11/tdd-tests-are-not-unit-tests.aspx
Unit testing with Visual Studio 2008
http://www.geekzone.co.nz/vs2008/4819
A Unit Testing Walkthrough with Visual Studio Team Test
http://msdn.microsoft.com/en-us/library/ms379625(VS.80).aspx
The first noteworthy characteristic of Listing 6 is the addition of the DataSourceAttribute in which the connection string, table name, and access order are specified. In this listing we use a database file name to identify the database. The advantage of this is that the file will travel with the test project, assuming it is updated to be a relative path.
The second important characteristic is the TestContext.DataRow calls. TestContext is a property that the generator provided when we ran the Create Tests wizard. The property is automatically assigned by the test execution engine at runtime so that within a test we can access data associated with the test context, As Figure 7 shows, the TestContext provides data such as the TestDirectory and TestName, along with methods such as BeginTimer() and EndTimer(). What is most significant for the ChangePasswordTest() method is the DataRow property. Because the ChangePasswordTest() method is decorated with DataSourceAttribute, it will be called once for each record returned from the table specified by the attribute. This enables the test code to use the data within an executing test and have the test repeat for each record inserted into the LogonInfoTest table. If the table contains four records, then the test will be executed four separate times.
2010年7月16日星期五
Differentiate logical and physical database?
http://wiki.answers.com/Q/Differentiate_logical_and_physical_database
After all business requirements have been gathered for a proposed database, they must be modeled. Models are created to visually represent the proposed database so that business requirements can easily be associated with database objects to ensure that all requirements have been completely and accurately gathered. Different types of diagrams are typically produced to illustrate the business processes, rules, entities, and organizational units that have been identified. These diagrams often include entity relationship diagrams, process flow diagrams, and server model diagrams. An entity relationship diagram (ERD) represents the entities, or groups of information, and their relationships maintained for a business. Process flow diagrams represent business processes and the flow of data between different processes and entities that have been defined. Server model diagrams represent a detailed picture of the database as being transformed from the business model into a relational database with tables, columns, and constraints. Basically, data modeling serves as a link between business needs and system requirements.
Two types of data modeling are as follows:
•Logical modeling
•Physical modeling
If you are going to be working with databases, then it is important to understand the difference between logical and physical modeling, and how they relate to one another. Logical and physical modeling are described in more detail in the following subsections.
Logical Modeling
Logical modeling deals with gathering business requirements and converting those requirements into a model. The logical model revolves around the needs of the business, not the database, although the needs of the business are used to establish the needs of the database. Logical modeling involves gathering information about business processes, business entities (categories of data), and organizational units. After this information is gathered, diagrams and reports are produced including entity relationship diagrams, business process diagrams, and eventually process flow diagrams. The diagrams produced should show the processes and data that exists, as well as the relationships between business processes and data. Logical modeling should accurately render a visual representation of the activities and data relevant to a particular business.
The diagrams and documentation generated during logical modeling is used to determine whether the requirements of the business have been completely gathered. Management, developers, and end users alike review these diagrams and documentation to determine if more work is required before physical modeling commences.
Typical deliverables of logical modeling include
•Entity relationship diagrams
An Entity Relationship Diagram is also referred to as an analysis ERD. The point of the initial ERD is to provide the development team with a picture of the different categories of data for the business, as well as how these categories of data are related to one another.
•Business process diagrams
The process model illustrates all the parent and child processes that are performed by individuals within a company. The process model gives the development team an idea of how data moves within the organization. Because process models illustrate the activities of individuals in the company, the process model can be used to determine how a database application interface is design.

Other business process sample can be found at:
http://content.usa.visual-paradigm.com/media/documents/bpva20ug/html/Ch06_Business_Process_Diagram_Samples/Ch06_Business_Process_Diagram_Samples.html
•User feedback documentation
Physical Modeling
Physical modeling involves the actual design of a database according to the requirements that were established during logical modeling. Logical modeling mainly involves gathering the requirements of the business, with the latter part of logical modeling directed toward the goals and requirements of the database. Physical modeling deals with the conversion of the logical, or business model, into a relational database model. When physical modeling occurs, objects are being defined at the schema level. A schema is a group of related objects in a database. A database design effort is normally associated with one schema.
During physical modeling, objects such as tables and columns are created based on entities and attributes that were defined during logical modeling. Constraints are also defined, including primary keys, foreign keys, other unique keys, and check constraints. Views can be created from database tables to summarize data or to simply provide the user with another perspective of certain data. Other objects such as indexes and snapshots can also be defined during physical modeling. Physical modeling is when all the pieces come together to complete the process of defining a database for a business.
Physical modeling is database software specific, meaning that the objects defined during physical modeling can vary depending on the relational database software being used. For example, most relational database systems have variations with the way data types are represented and the way data is stored, although basic data types are conceptually the same among different implementations. Additionally, some database systems have objects that are not available in other database systems.
Typical deliverables of physical modeling include the following:
•Server model diagrams
The server model diagram shows tables, columns, and relationships within a database.
•User feedback documentation Database design documentation
Conclusion
Understanding the difference between logical and physical modeling will help you build better organized and more effective database systems.
After all business requirements have been gathered for a proposed database, they must be modeled. Models are created to visually represent the proposed database so that business requirements can easily be associated with database objects to ensure that all requirements have been completely and accurately gathered. Different types of diagrams are typically produced to illustrate the business processes, rules, entities, and organizational units that have been identified. These diagrams often include entity relationship diagrams, process flow diagrams, and server model diagrams. An entity relationship diagram (ERD) represents the entities, or groups of information, and their relationships maintained for a business. Process flow diagrams represent business processes and the flow of data between different processes and entities that have been defined. Server model diagrams represent a detailed picture of the database as being transformed from the business model into a relational database with tables, columns, and constraints. Basically, data modeling serves as a link between business needs and system requirements.
Two types of data modeling are as follows:
•Logical modeling
•Physical modeling
If you are going to be working with databases, then it is important to understand the difference between logical and physical modeling, and how they relate to one another. Logical and physical modeling are described in more detail in the following subsections.
Logical Modeling
Logical modeling deals with gathering business requirements and converting those requirements into a model. The logical model revolves around the needs of the business, not the database, although the needs of the business are used to establish the needs of the database. Logical modeling involves gathering information about business processes, business entities (categories of data), and organizational units. After this information is gathered, diagrams and reports are produced including entity relationship diagrams, business process diagrams, and eventually process flow diagrams. The diagrams produced should show the processes and data that exists, as well as the relationships between business processes and data. Logical modeling should accurately render a visual representation of the activities and data relevant to a particular business.
The diagrams and documentation generated during logical modeling is used to determine whether the requirements of the business have been completely gathered. Management, developers, and end users alike review these diagrams and documentation to determine if more work is required before physical modeling commences.
Typical deliverables of logical modeling include
•Entity relationship diagrams
An Entity Relationship Diagram is also referred to as an analysis ERD. The point of the initial ERD is to provide the development team with a picture of the different categories of data for the business, as well as how these categories of data are related to one another.

•Business process diagrams
The process model illustrates all the parent and child processes that are performed by individuals within a company. The process model gives the development team an idea of how data moves within the organization. Because process models illustrate the activities of individuals in the company, the process model can be used to determine how a database application interface is design.

Other business process sample can be found at:
http://content.usa.visual-paradigm.com/media/documents/bpva20ug/html/Ch06_Business_Process_Diagram_Samples/Ch06_Business_Process_Diagram_Samples.html
•User feedback documentation
Physical Modeling
Physical modeling involves the actual design of a database according to the requirements that were established during logical modeling. Logical modeling mainly involves gathering the requirements of the business, with the latter part of logical modeling directed toward the goals and requirements of the database. Physical modeling deals with the conversion of the logical, or business model, into a relational database model. When physical modeling occurs, objects are being defined at the schema level. A schema is a group of related objects in a database. A database design effort is normally associated with one schema.
During physical modeling, objects such as tables and columns are created based on entities and attributes that were defined during logical modeling. Constraints are also defined, including primary keys, foreign keys, other unique keys, and check constraints. Views can be created from database tables to summarize data or to simply provide the user with another perspective of certain data. Other objects such as indexes and snapshots can also be defined during physical modeling. Physical modeling is when all the pieces come together to complete the process of defining a database for a business.
Physical modeling is database software specific, meaning that the objects defined during physical modeling can vary depending on the relational database software being used. For example, most relational database systems have variations with the way data types are represented and the way data is stored, although basic data types are conceptually the same among different implementations. Additionally, some database systems have objects that are not available in other database systems.
Typical deliverables of physical modeling include the following:
•Server model diagrams
The server model diagram shows tables, columns, and relationships within a database.
•User feedback documentation Database design documentation
Conclusion
Understanding the difference between logical and physical modeling will help you build better organized and more effective database systems.
DataView Sorting Filtering and DataBinding in ADO.NET 2.0 - Converting DataView to Table - ADO.NET Tutorials
http://davidhayden.com/blog/dave/archive/2006/02/11/2798.aspx
you will probably want to use the DataView Object in ADO.NET 2.0 for sorting and filtering a DataTable, because the DataView is bindable whereas the array of DataRows[] returned by the methods of the DataTable is not.
public DataView(DataTable table, string RowFilter, string Sort, DataViewRowState RowState)
Here is an example of using the full constructor to create a view from the Customers Table in the Northwind Database such that it only contains customers from a specific region ( SP ) and country ( Brazil ), sorted by ContactName, and including only current rows.
string connectionString = "..Nortwind Connection String..";
DataTable customers = new DataTable("Customers");
using (SqlConnection connection = new SqlConnection(connectionString))
{
SqlCommand selectAllCustomers = connection.CreateCommand();
selectAllCustomers.CommandText = "SELECT * FROM [Customers]";
connection.Open();
customers.Load(selectAllCustomers.ExecuteReader(CommandBehavior.CloseConnection));
}
DataView dv = new DataView(customers,"Region = 'SP' and Country = 'Brazil'", "ContactName", DataViewRowState.CurrentRows);
dataGridView1.DataSource = dv;
Now you don't have to use the full DataView Constructor, you can also specify individual properties based on your needs. For example, we can delete two records from the same Customers DataTable and then only view those deleted records in the DataGridView:
string connectionString = "..Nortwind Connection String..";
DataTable customers = new DataTable("Customers");
using (SqlConnection connection = new SqlConnection(connectionString))
{
SqlCommand selectAllCustomers = connection.CreateCommand();
selectAllCustomers.CommandText = "SELECT * FROM [Customers]";
connection.Open();
customers.Load(selectAllCustomers.ExecuteReader(CommandBehavior.CloseConnection));
}
DataView dv = new DataView(categories);
dv.Table.Rows[0].Delete();
dv.Table.Rows[1].Delete();
dv.RowStateFilter = DataViewRowState.Deleted;
dataGridView1.DataSource = dv;
you will probably want to use the DataView Object in ADO.NET 2.0 for sorting and filtering a DataTable, because the DataView is bindable whereas the array of DataRows[] returned by the methods of the DataTable is not.
public DataView(DataTable table, string RowFilter, string Sort, DataViewRowState RowState)
Here is an example of using the full constructor to create a view from the Customers Table in the Northwind Database such that it only contains customers from a specific region ( SP ) and country ( Brazil ), sorted by ContactName, and including only current rows.
string connectionString = "..Nortwind Connection String..";
DataTable customers = new DataTable("Customers");
using (SqlConnection connection = new SqlConnection(connectionString))
{
SqlCommand selectAllCustomers = connection.CreateCommand();
selectAllCustomers.CommandText = "SELECT * FROM [Customers]";
connection.Open();
customers.Load(selectAllCustomers.ExecuteReader(CommandBehavior.CloseConnection));
}
DataView dv = new DataView(customers,"Region = 'SP' and Country = 'Brazil'", "ContactName", DataViewRowState.CurrentRows);
dataGridView1.DataSource = dv;
Now you don't have to use the full DataView Constructor, you can also specify individual properties based on your needs. For example, we can delete two records from the same Customers DataTable and then only view those deleted records in the DataGridView:
string connectionString = "..Nortwind Connection String..";
DataTable customers = new DataTable("Customers");
using (SqlConnection connection = new SqlConnection(connectionString))
{
SqlCommand selectAllCustomers = connection.CreateCommand();
selectAllCustomers.CommandText = "SELECT * FROM [Customers]";
connection.Open();
customers.Load(selectAllCustomers.ExecuteReader(CommandBehavior.CloseConnection));
}
DataView dv = new DataView(categories);
dv.Table.Rows[0].Delete();
dv.Table.Rows[1].Delete();
dv.RowStateFilter = DataViewRowState.Deleted;
dataGridView1.DataSource = dv;
SCOPE_IDENTITY() vs. @@IDENTITY - Retrieving Identity for Most Recently Added Row in Table
http://davidhayden.com/blog/dave/archive/2006/01/17/2736.aspx
Although @@IDENTITY is one of those common practices in SQL Server 7, which does not have a SCOPE_IDENTITY() function, it is no longer the accepted way to get the identity of the most recently added row in a table in SQL Server 2000 and SQL Server 2005.
@@IDENTITY returns the most recently created identity for your current connection, not necessarily the identity for the recently added row in a table. You could have a situation where there is a trigger that inserts a new record in a Logs Table, for example, when your Stored Procedure or INSERT SQL Statement inserts a record in the Orders Table. If you use @@IDENTITY to retrieve the identity of the new order, you will actually get the identity of the record added into the Log Table and not the Orders Table, which will create a nasty, nasty bug in your data access layer.
To avoid the potential problems associated with someone adding a trigger later on, always use SCOPE_IDENTITY() to return the identity of the recently added row in your INSERT SQL Statement or Stored Procedure.
Although @@IDENTITY is one of those common practices in SQL Server 7, which does not have a SCOPE_IDENTITY() function, it is no longer the accepted way to get the identity of the most recently added row in a table in SQL Server 2000 and SQL Server 2005.
@@IDENTITY returns the most recently created identity for your current connection, not necessarily the identity for the recently added row in a table. You could have a situation where there is a trigger that inserts a new record in a Logs Table, for example, when your Stored Procedure or INSERT SQL Statement inserts a record in the Orders Table. If you use @@IDENTITY to retrieve the identity of the new order, you will actually get the identity of the record added into the Log Table and not the Orders Table, which will create a nasty, nasty bug in your data access layer.
To avoid the potential problems associated with someone adding a trigger later on, always use SCOPE_IDENTITY() to return the identity of the recently added row in your INSERT SQL Statement or Stored Procedure.
2010年7月15日星期四
ASP.NET Caching Features
http://msdn.microsoft.com/en-us/library/xsbfdd8c(VS.71).aspx
One of the most important factors in building high-performance, scalable Web applications is the ability to store items, whether data objects, pages, or parts of a page, in memory the initial time they are requested. You can store these items on the Web server or other software in the request stream, such as the proxy server or browser.
ASP.NET provides two types of caching: The first is called output caching, which allows you to store dynamic page and user control responses;
<%@ OutputCache Duration="60" VaryByParam="None" %>
The required VaryByParam attribute allows you to vary the cached output depending on GET query string or form POST parameters.
The second type of caching is traditional application data caching, which you can use to programmatically store arbitrary objects, such as data sets, to server memory.
Cache.Insert("MyData1", connectionString, new CacheDependency(Server.MapPath(\\myServer\myConfig.xml)));
Following code show how application responds when a data source or data set is not in the Cache:
DataView Source = (DataView)Cache["MyData1"];
if (Source == null) {
SqlConnection myConnection = new SqlConnection("server=localhost;Integrated Security=SSPI;database=pubs");
SqlDataAdapter myCommand = new SqlDataAdapter("select * from Authors", myConnection);
DataSet ds = new DataSet();
myCommand.Fill(ds, "Authors");
Source = new DataView(ds.Tables["Authors"]);
Cache["MyData1"] = Source;
}
MyDataGrid.DataSource=Source;
MyDataGrid.DataBind();
One of the most important factors in building high-performance, scalable Web applications is the ability to store items, whether data objects, pages, or parts of a page, in memory the initial time they are requested. You can store these items on the Web server or other software in the request stream, such as the proxy server or browser.
ASP.NET provides two types of caching: The first is called output caching, which allows you to store dynamic page and user control responses;
<%@ OutputCache Duration="60" VaryByParam="None" %>
The required VaryByParam attribute allows you to vary the cached output depending on GET query string or form POST parameters.
The second type of caching is traditional application data caching, which you can use to programmatically store arbitrary objects, such as data sets, to server memory.
Cache.Insert("MyData1", connectionString, new CacheDependency(Server.MapPath(\\myServer\myConfig.xml)));
Following code show how application responds when a data source or data set is not in the Cache:
DataView Source = (DataView)Cache["MyData1"];
if (Source == null) {
SqlConnection myConnection = new SqlConnection("server=localhost;Integrated Security=SSPI;database=pubs");
SqlDataAdapter myCommand = new SqlDataAdapter("select * from Authors", myConnection);
DataSet ds = new DataSet();
myCommand.Fill(ds, "Authors");
Source = new DataView(ds.Tables["Authors"]);
Cache["MyData1"] = Source;
}
MyDataGrid.DataSource=Source;
MyDataGrid.DataBind();
ASP.NET Cookies Overview
http://msdn.microsoft.com/en-us/library/ms178194.aspx
A cookie is a small bit of text that accompanies requests and pages as they go between the Web server and browser. The cookie contains information the Web application can read whenever the user visits the site.
For example, if a user requests a page from your site and your application sends not just a page, but also a cookie containing the date and time, when the user's browser gets the page, the browser also gets the cookie, which it stores in a folder on the user's hard disk.
Later, if user requests a page from your site again, when the user enters the URL the browser looks on the local hard disk for a cookie associated with the URL. If the cookie exists, the browser sends the cookie to your site along with the page request. Your application can then determine the date and time that the user last visited the site. You might use the information to display a message to the user or check an expiration date.
Cookies are used for many purposes, all relating to helping the Web site remember users. For example, a site conducting a poll might use a cookie simply as a Boolean value to indicate whether a user's browser has already participated in voting so that the user cannot vote twice. A site that asks a user to log on might use a cookie to record that the user already logged on so that the user does not have to keep entering credentials.
If you do not set the cookie's expiration, the cookie is created but it is not stored on the user's hard disk. Instead, the cookie is maintained as part of the user's session information. When the user closes the browser, the cookie is discarded. A non-persistent cookie like this is useful for information that needs to be stored for only a short time or that for security reasons should not be written to disk on the client computer. For example, non-persistent cookies are useful if the user is working on a public computer, where you do not want to write the cookie to disk.
Most browsers support cookies of up to 4096 bytes.
A cookie limitation that you might encounter is that users can set their browser to refuse cookies.you might have to avoid cookies altogether and use a different mechanism to store user-specific information. A common method for storing user information is session state, but session state depends on cookies, as explained later in the section "Cookies and Session State."
Before trying to get the value of a cookie, you should make sure that the cookie exists; if the cookie does not exist, you will get a NullReferenceException exception. Notice also that the HtmlEncode method was called to encode the contents of a cookie before displaying it in the page. This makes certain that a malicious user has not added executable script into the cookie.
A cookie is a small bit of text that accompanies requests and pages as they go between the Web server and browser. The cookie contains information the Web application can read whenever the user visits the site.
For example, if a user requests a page from your site and your application sends not just a page, but also a cookie containing the date and time, when the user's browser gets the page, the browser also gets the cookie, which it stores in a folder on the user's hard disk.
Later, if user requests a page from your site again, when the user enters the URL the browser looks on the local hard disk for a cookie associated with the URL. If the cookie exists, the browser sends the cookie to your site along with the page request. Your application can then determine the date and time that the user last visited the site. You might use the information to display a message to the user or check an expiration date.
Cookies are used for many purposes, all relating to helping the Web site remember users. For example, a site conducting a poll might use a cookie simply as a Boolean value to indicate whether a user's browser has already participated in voting so that the user cannot vote twice. A site that asks a user to log on might use a cookie to record that the user already logged on so that the user does not have to keep entering credentials.
If you do not set the cookie's expiration, the cookie is created but it is not stored on the user's hard disk. Instead, the cookie is maintained as part of the user's session information. When the user closes the browser, the cookie is discarded. A non-persistent cookie like this is useful for information that needs to be stored for only a short time or that for security reasons should not be written to disk on the client computer. For example, non-persistent cookies are useful if the user is working on a public computer, where you do not want to write the cookie to disk.
Most browsers support cookies of up to 4096 bytes.
A cookie limitation that you might encounter is that users can set their browser to refuse cookies.you might have to avoid cookies altogether and use a different mechanism to store user-specific information. A common method for storing user information is session state, but session state depends on cookies, as explained later in the section "Cookies and Session State."
Before trying to get the value of a cookie, you should make sure that the cookie exists; if the cookie does not exist, you will get a NullReferenceException exception. Notice also that the HtmlEncode method was called to encode the contents of a cookie before displaying it in the page. This makes certain that a malicious user has not added executable script into the cookie.
ASP.NET Session State Overview
http://msdn.microsoft.com/en-us/library/ms972429.aspx
We can configure the ASP.NET session state as cookieless session state. Essentially this feature allows sites whose clients choose not to use cookies to take advantage of ASP.NET session state.
This is done by modifying the URL with an ID that uniquely identifies the session:
http://localhost/(lit3py55t21z5v55vlm25s55)/Application/SessionState.aspx
ASP.NET will modify relative links found within the page and embed this ID. Thus, as long as the user follows the path of links the site provides, session state can be maintained. However, if the end user re-writes the URL, the session state instance will most likely be lost.
We can configure the ASP.NET session state as cookieless session state. Essentially this feature allows sites whose clients choose not to use cookies to take advantage of ASP.NET session state.
This is done by modifying the URL with an ID that uniquely identifies the session:
http://localhost/(lit3py55t21z5v55vlm25s55)/Application/SessionState.aspx
ASP.NET will modify relative links found within the page and embed this ID. Thus, as long as the user follows the path of links the site provides, session state can be maintained. However, if the end user re-writes the URL, the session state instance will most likely be lost.
TRANSACTION ISOLATION LEVEL
SET TRANSACTION ISOLATION LEVEL
{ READ UNCOMMITTED
| READ COMMITTED
| REPEATABLE READ
| SNAPSHOT
| SERIALIZABLE
}
[ ; ]
READ UNCOMMITTED
Specifies that statements can read rows that have been modified by other transactions but not yet committed.
READ COMMITTED
Specifies that statements cannot read data that has been modified but not committed by other transactions. This prevents dirty reads.
REPEATABLE READ
Specifies that statements cannot read data that has been modified but not yet committed by other transactions and that no other transactions can modify data that has been read by the current transaction until the current transaction completes.
SNAPSHOT
Specifies that data read by any statement in a transaction will be the transactionally consistent version of the data that existed at the start of the transaction. Data modifications made by other transactions after the start of the current transaction are not visible to statements executing in the current transaction.
SERIALIZABLE
Specifies the following:
1. Statements cannot read data that has been modified but not yet committed by other transactions.
2. No other transactions can modify data that has been read by the current transaction until the current transaction completes.
3. Other transactions cannot insert new rows with key values that would fall in the range of keys read by any statements in the current transaction until the current transaction completes.
SET TRANSACTION ISOLATION LEVEL REPEATABLE READ;
BEGIN TRANSACTION;
...
COMMIT TRANSACTION;
{ READ UNCOMMITTED
| READ COMMITTED
| REPEATABLE READ
| SNAPSHOT
| SERIALIZABLE
}
[ ; ]
READ UNCOMMITTED
Specifies that statements can read rows that have been modified by other transactions but not yet committed.
READ COMMITTED
Specifies that statements cannot read data that has been modified but not committed by other transactions. This prevents dirty reads.
REPEATABLE READ
Specifies that statements cannot read data that has been modified but not yet committed by other transactions and that no other transactions can modify data that has been read by the current transaction until the current transaction completes.
SNAPSHOT
Specifies that data read by any statement in a transaction will be the transactionally consistent version of the data that existed at the start of the transaction. Data modifications made by other transactions after the start of the current transaction are not visible to statements executing in the current transaction.
SERIALIZABLE
Specifies the following:
1. Statements cannot read data that has been modified but not yet committed by other transactions.
2. No other transactions can modify data that has been read by the current transaction until the current transaction completes.
3. Other transactions cannot insert new rows with key values that would fall in the range of keys read by any statements in the current transaction until the current transaction completes.
SET TRANSACTION ISOLATION LEVEL REPEATABLE READ;
BEGIN TRANSACTION;
...
COMMIT TRANSACTION;
2010年7月14日星期三
订阅:
评论 (Atom)