MS SQL Paging records using Stored Procedure and DataGrid custom paging

February 25, 2009
Data grid with custom paging

Data grid with custom paging

Demo Source: Download (C# asp.net  1.1)

Create Store Procedure in NorthWind database:

CREATE PROC GetProductsByPage
@CurrentPage tinyint,–Set what page will be displayed
@PageSize tinyint,–Number of records per page
@TotalRecords int OUTPUT–Count total records
AS
–We won’t need to get the number of rows inserted to #Temp
SET NOCOUNT ON

–Find out the first and the last record
DECLARE @FirstRec int
DECLARE @LastRec int

SET @FirstRec = (@CurrentPage – 1) * @PageSize
SET @LastRec = (@CurrentPage * @PageSize + 1)

–Create Temp table
CREATE TABLE #Temp
(
TempID int IDENTITY PRIMARY KEY,
ProductID int ,
ProductName nvarchar(40),
QuantityPerUnit nvarchar(20),
UnitPrice money
)

–Insert rows from Products to Temp
INSERT INTO #Temp(ProductID, ProductName, QuantityPerUnit, UnitPrice)
SELECT ProductID, ProductName, QuantityPerUnit, UnitPrice FROM Products ORDER BY ProductID

–Return the set of paged records
SELECT ProductID, ProductName, QuantityPerUnit, UnitPrice
FROM #Temp
WHERE TempID > @FirstRec AND TempID<@LastRec

–Return total of records that we have
SELECT @TotalRecords = COUNT(*)
FROM #Temp
GO


Payment Modules with osCommerce

January 15, 2009

I have had a fair bit of experience now with Payment Modules under osCommerce. I have used publicly available payment modules as well as writing my own (for Australian eSec/Securepay, Westpac Webadvantage and Mastercard Internet Gateway Services – MIGS).

I have to say that a lot of the modules aren’t correctly documented and often take the quickest approach to doing a problem, without considering future maintenance or implementing good industry practices. Overall the osCommerce package has, in my opinion, in general, become more of a nightmare than a solution for anything you want to do that slightly changes from the standard package they provide.

But instead of turning this into a “I am so over osCommerce” post I am going to discuss coding up a Payment Method that will suit the requirements of your client or your site.

The Payment Module

The payment module is a way of creating a custom hook point for handling payment by a specific means, such as accepting payment via PayPal or through an Online Credit Card Gateway. It is written flexible enough to cater for 98% of situations and has frameworked multilanguage support. A payment module is formed of two files, the Payment Module Language file as well as the Payment File Class.

The payment module language files are located in

“includes/languages/[english]/modules/payment” and should to correspond to the same name as your class file. It contains series of define(); calls to setup the various language requirements that you need.

The payment module class files are located in

“includes/modules/payment” and are typically named similar to “cc_via_whatever.php” or something more descriptive. This is the file that will handle our processing.

You will need to request from your payment gateway provider an integration guide. Any payment provider will be able to provide you this information and should provide sufficient support for you to diagnose the process.

The next step is to analyse the flow of the Payment Module Class. This is extremely important for you to understand as you will need to disect your payment integration into the correct functions of your Payment Class. Ensure that you protect your clients sensitive information and never rely on hidden form fields (!).
The order in which the payment module is executed occurs similar to below:

Constructor (function cc_via_whatever): Purpose is to initialise requirements of osCommerce. The variables that it wants you to configure include:

- $this->code = (same as your class file name prepend, eg, “cc_via_whatever”)
- $this->title = (Title of the payment module, EG “Payment Via Credit Card Facilities Online”, you will see this appear on your website frontend)
- $this->description = (a more verbose explaination of the payment module)
- $this->enabled = (This is very important to set true or false. I usually check to ensure all my Admin controlled variables are set before making this module enabled)
- $this->form_action_url = (Where to submit the form contents to once hit submit)
- $this->sort_order = (The sort order of this module in correspondance to others)

function update_status: Purpose it so check whether this payment module is available during runtime with an order.
Usually this method will analyse whether the payment module is valid within this clients zone. This is usually a generic call, so you can reference other example payment modules.

First Stage, Making Selection of the Payment Module

function javascript_validation: Purpose is to check the contents of the submitted payment details when this option is selected for payment.
This is usually fairly generic between the credit card modules, but you will need to ensure that your naming of your files remain the same as well.

function selection: Purpose is to provide a set of form information when the payment module is selected. The form information is used to render the form required fields, such as Credit Card number etc. The javascript validation provided in the above javascript_validation method will work off the field names setup here. If you are using a bank hosted integration model, or one that does not require user input of credit card you can return only the id and module. Check another payment module for the syntax.
function pre_confirmation_check: Purpose is to validate the details that have been submitted for the form that we created above. This needs to be very thorough. If you are using this payment method for the validation of a Credit Card you may like to make use of the validation class cc_validation.php bundled with osCommerce. Other payment modules will help you which its use. If the form fields don’t validate, this function will redirect the user back to the payment selection screen.

Second Stage, Confirming the order

function confirm: Purpose is to confirm to the user the details that will be used to process the order. Once again this is in an array format that defines keys that will be read in on the confirmation page.

function process_button: This allows us to place in hidden form fields into the confirmation page. These are provided to you by your payment gateway. You will need to carefully analyse which fields need to be placed here – as they are parsed through the request (only) to the next process:

Third Stage, Processing the payment

function before_process: This is where all of our actions go for processing the payment (prior to the order being saved). If you are using a Bank Hosted model this is called after the user has been to the bank and is returning. You will need to validate the request (eg, $_GET/$_POST) to ensure that the bank responded with the correct details. If you are submitting to the bank directly using CURL or similar, you will perform you actions here also to determine if the order should be continued to be processed, or to divert the user back to the payment details screen. This method doesn’t return a value, instead you will need to perform your validation and redirect if necessary. Otherwise allow the function to terminate and it will continue to process the order.

function after_process: This is called after the order has been saved. I don’t usually have a need for this method.

Misc Methods required for the payment module to integrate into osCommerce

function get_error: Create an associative array to house the error. Check syntax from existing payment module

function check: Checks whether the payment has been “installed” through the admin panel. You can determine this by checking for configuration_values which get inserted into the database when the user hits “install”.

function install: Installs the configuration keys into the database. This is where you define the fields to be collected from the adminsitrator user, such as Merchant ID’s etc.

function remove: Removes the configuration keys from the database, called when they hit “remove” in the backend.

function keys: Defines an array containing the configuration key keys that are used by the payment module.

For an example for one that I contributed to osCommerce for MIGS – ANZ, Bendigo use etc checkout the link to the payment module: MIGS Payment Module

I recommend for people to indicate on their module: Proper PHPDoc tags for functions, break up the method access into accessor style methods, try to leave a much notes for future developers (even yourself) such as “//” sections that indicate what you are doing etc. Also ensure to TODO notes where you have not completed a section of the integration, and also quote any documentation versions that you have used.

Lastly to complete the Payment Module you should include correct documentation that outlines how to install via FTP etc.


Fix Ajax + IE Caching Problem

January 8, 2009

The problem : Using XML HTTP Request (method=”get”), Internet Explorer caches response sent back from the server script.
Solution: Choose one of three methods below:

Method 1:  Server side

<?
//PHP Requests Handler

header (“Expires: Mon, 26 Jul 1997 05:00:00 GMT”);    // Date in the past
header (“Last-Modified: ” . gmdate(“D, d M Y H:i:s”) . ” GMT”);
header (“Cache-Control: no-cache, must-revalidate”);  // HTTP/1.1
header (“Pragma: no-cache”);
//header (“Content-type: application/xml”); //uncomment this line if you plan to send XML

//……………….

?>

Method 2: Client side
Add a random string to your request url, i personally like this method :

<script type=”text/javascript”>

var url = ‘ajaxdata.php?action=doSomething’;
var randomString = String(new Date().getTime()).replace(/\D/gi,”);
url = url + ‘?’ + randomString;

//send ajax request…

</script>

Method 3: Client side
Send a post request instead of get request, post requests are not cached.




Indexed Views in SQL Server 2000

September 17, 2008

In this excellent article Doug covers the basics of creating an Indexed View. He also goes into detail on sizing considerations and when and when not to use an Indexed View.

<!–


–>

With SQL Server 2000 (Enterprise Edition), Microsoft has introduced the concept of Indexed Views, which can make your applications and queries run faster in the right circumstances.

Why Indexed Views?

Views have been available throughout the history of Microsoft SQL Server. However, using views that return very large result sets can lead to poor performance, as the result set is not indexed and the entire result must be table scanned if the view is used in a join or a subquery of a T-SQL command. Additionally, products like Oracle have come out with the concept of a Materialized View that give an additional performance boost by being able to have indexes built on a view. So in the continuing evolution of the SQL Server product line and in response to Oracle’s Materialized View, Microsoft SQL Server 2000 has a new feature called the View Index. View Indexes give the product the capability to define an index on a view. Additionally, SQL Server View Indexes are dynamic in that changes to the data in the base tables are automatically reflected in the indexed view. Also the SQL Server query optimizer will try to use an indexed view even if the view is not referenced in the from clause of a T-SQL command. These features are not available in Oracle’s Materialized Views.

Before SQL Server 2000, what was a View?

Typically a view is thought of as a virtual table, or a stored query. The results of using a view are not permanently stored in the database. The data accessed through a view is actually constructed using standard T-SQL select command and can come from one to many different base tables or even other views. This T-SQL select command is stored as a database object (a view). Developers can use the results from the view by referencing the view name in T-SQL statements the same way they would reference a real table. When referenced, the stored T-SQL that represents the view is merged with the referencing T-SQL code and executed to come up with the final results. Views have additional benefits of:

  1. Views provide a security mechanism by subsetting the data by rows (All Active Customers, all customers in a certain state).
  2. Views provide a security mechanism by subsetting the data by columns (Payroll fields not shown in the Employee Phone List View).
  3. Views can simplify complex queries into a single reference. Complex Join operations that can make a normalized database design of several tables into a single row in the result set of the view. This is great for reporting tools like Crystal and Cognos.
  4. Views give us aggregation capabilities (Min, Max, Count, Sum) where the data is not stored but calculated.
  5. Views can create other calculated fields based on values in the real underlying tables.
  6. Views can reference another view as one its “Base Tables”.
  7. Views can hide the complexity of partitioned data (Sales from 1998 are in the 1998 table, Sales from 1999 are in the 1999 table, Sales from 2000 are in the Current Table) .
  8. Views can be updateable in certain situations (only update to 1 of the base tables!).
  9. Views do not incur overhead of additional permanent storage.

What are SQL Server 2000 Indexed views?

Views in SQL Server 2000 are very similar to those in previous versions with a few major exceptions when using Indexed views. When a clustered index is created on the view, SQL Server immediately allocates storage space to store the results of the view. You can then treat the view like any other table by adding additional nonclustered indexes.

What are the requirements for Indexed views?

There are several requirements that you must take into consideration when using Indexed views.

  1. View definition must always return the same results from the same underlying data.
  2. Views cannot use non-deterministic functions.
  3. The first index on a View must be a clustered, UNIQUE index.
  4. If you use Group By, you must include the new COUNT_BIG(*) in the select list.
  5. View definition cannot contain the following
    1. TOP
    2. Text, ntext or image columns
    3. DISTINCT
    4. MIN, MAX, COUNT, STDEV, VARIANCE, AVG
    5. SUM on a nullable expression
    6. A derived table
    7. Rowset function
    8. Another view
    9. UNION
    10. Subqueries, outer joins, self joins
    11. Full-text predicates like CONTAIN or FREETEXT
    12. COMPUTE or COMPUTE BY
    13. Cannot include order by in view definition

Notice that Indexed Views change the very essence of what a view was before this version of Sql Server. First, the data represented by the view is actually stored in the database. Secondly, the view definition must always return the same results for the same underlying data and all functions and expressions must be deterministic no matter what the current session settings.

To make sure that you can meet this requirement, the following session options must be set when you create an index view, when you modify any of the tables included in an indexed view or when the optimizer decides to use the indexed view as part of a query plan. Session Options that must be on

ANSI_NULLS
ANSI_PADDING
ANSI_WARNINGS
ARITHABORT
CONCAT_NULL_YEILDS_NULL
QUOTED_IDENTIFIERS

Session options that must be off

NUMERIC_ROUNDABORT

Functions like GetDate(), rand() are non-deterministic because of different session settings can return different values and the settings for one user may not be the same as for another. The list of deterministic and non-deterministic functions will be included in the final version of Books Online for SQL Server 2000. (Look for topic Deterministic and Nondeterministic Functions in the Books Online)

Besides these restrictions, the underlying tables that make up the view must be protected from schema changes. Part of the syntax of the create view command is the “with SCHEMABINDING” phrase. This is required to create a View Index and this will prevent the dropping or altering of tables participating in an Indexed View. Note that dropping the clustered index of an Indexed View will return it to the standard SQL view as it was as described above in the section Before SQL Server 2000, what was a View?

How do I create an Indexed View?

  1. Make sure that session properties are properly set.
  2. Create a deterministic view with new SCHEMABINDING syntax.
  3. Create unique Clustered Index.
  4. Optionally, create additional nonclustered indexes.

Below you will find the code that you can paste into the Sql Server Query Analyzer to test this yourself. This example is based on the Northwind sample database.

-- Use the northwind database
USE NORTHWIND
GO

-- Make sure that all of the session settings are set properly
IF sessionproperty('ARITHABORT') = 0 SET ARITHABORT ON
IF sessionproperty('CONCAT_NULL_YIELDS_NULL') = 0 SET CONCAT_NULL_YIELDS_NULL ON
IF sessionproperty('QUOTED_IDENTIFIER') = 0 SET QUOTED_IDENTIFIER ON
IF sessionproperty('ANSI_NULLS') = 0 SET ANSI_NULLS ON
IF sessionproperty('ANSI_PADDING') = 0 SET ANSI_PADDING ON
IF sessionproperty('ANSI_WARNINGS') = 0 SET ANSI_WARNINGS ON
IF sessionproperty('NUMERIC_ROUNDABORT') = 1 SET NUMERIC_ROUNDABORT OFF
go

-- Create the view, it must comply with the rules (deterministic)
CREATE VIEW PRODUCTS_BY_CUSTOMER WITH SCHEMABINDING AS
select customers.companyname,
products.productname,
sum(odetail.unitprice*odetail.quantity) as TotalPurchase,
count_big(*) as cnt
from dbo."order details" as odetail
inner join dbo.orders as omain
on omain.orderid = odetail.orderid
INNER join dbo.customers as customers
on customers.customerid = omain.customerid
INNER join dbo.products as products
on products.productid = odetail.productid
group by
customers.companyname,
products.productname
go

-- the following statement will cause an error if the view has not been
-- indexed
--EXEC SP_SPACEUSED 'PRODUCTS_BY_CUSTOMER'
--Server: Msg 15235, Level 16, State 1, Procedure sp_spaceused, Line 91
--Views do not have space allocated.

-- Check to see if the indexes can be created
if ObjectProperty(object_id('products_by_customer'),'IsIndexable') = 1
BEGIN
-- Create a clustered index, it MUST be unique
CREATE UNIQUE CLUSTERED INDEX PRODUCTS_BY_CUSTOMER_UNIQUE ON
PRODUCTS_BY_CUSTOMER(COMPANYNAME, PRODUCTNAME)

EXEC SP_SPACEUSED 'PRODUCTS_BY_CUSTOMER'

-- Create NonClustered Indexes
CREATE INDEX PRODUCTS_BY_CUSTOMER_1 ON
PRODUCTS_BY_CUSTOMER(COMPANYNAME)

EXEC SP_SPACEUSED 'PRODUCTS_BY_CUSTOMER'

-- Create NonClustered Indexes
CREATE INDEX PRODUCTS_BY_CUSTOMER_2 ON
PRODUCTS_BY_CUSTOMER(PRODUCTNAME)

EXEC SP_SPACEUSED 'PRODUCTS_BY_CUSTOMER'

END

Please note the ObjectProperty(object_id('products_by_customer'),'IsIndexable') = 1 in the above code listing. This command will tell you if all of the requirements for indexing a view have been met so that you can programmatically determine if a view can be indexed or not.

Also note that no space is allocated in the database for this view until the clustered index is created. If you try to use the SP_SPACEUSED stored procedure on a view that is not indexed, you get an error. The results of the SP_SPACEUSED commands that are sprinkled throughout the above code listing gives the following results on my test machine.

  # of Rows Data Index Total Used
After Clustered Index Created 1685 168 kb 16 kb 184 kb
After NonClustered Index 1 1685 168 kb 168 kb 336 kb
After NonClustered Index 2 1685 168 kb 320 kb 488 kb

How do I use the Indexed View?

You can use the view like you would any other view. Also, the SQL Server query optimizer will attempt to use a View Index even if the view is not referenced in the from clause, although you can override this behavior with the Expand Views hint.

From the sample created in the above code example, you could use the view as follows

Example 1: select * from products_by_customer

Example 1 above lets the query optimizer determine whether or not to use the view and its indexes or to use the base tables. Surprising on my test machine, this example uses the base tables, not the Indexed View. The query optimizer is a complex piece of technology but it isn’t always perfect. Based on my testing with this sample data in the Northwind database, I had to use the (noexpand) hint seen in the next example to force the optimizer to use the View Index. The speed of this on my test machine was about 3 times faster with 1685 records. By increasing the number of records in the base tables (orders 3000 records and order details 224,696 records), I found that the query optimizer did use the View Index without specifying the hint and the resulting query speeds where approximately 50 times faster. The # of records in the view, after adding all of these records in the base tables, was 1880 records. I conclude that the query optimizer with a small number of records in the base table (Orders had about 830 and order details had about 2155 records when I started) lean towards using the base tables instead of the View index. More testing would be needed to nail down the break even point but this just points out why the hints are still around and how much faster performance can be when the View Indexes are used.

Example 2: select * from products_by_customer with (noexpand)

Example 2 uses a hint to force the query optimizer to consider only the view and its indexes in the execution plan.

Example 3: select * from products_by_customer option (Expand Views)

Example 3 uses a hint to force the query optimizer to expand all indexed views into their underlying Select statements so the optimizer won’t consider any View Indexes in the execution plan.

When would I want to use a View Index?

If you have an application that is a Data-Mart, Data-Mining or decision-support type application, you can improve performance with View Indexes. Applications that do any of the following may benefit as well:

  • Joins and aggregations of big tables
  • Repeated patterns of queries
  • Repeated aggregations on the same or overlapping sets of columns
  • Repeated joins of the same tables on the same keys

Also, situations where you might consider de-normalizing a set of tables by storing aggregate information in the parent table may be good situations to consider creating an aggregate view on the child table and creating the appropriate View Index. In essence, the Indexed View replaces your de-normalized fields and all the work of keeping this de-normalized aggregate field up to date is taken care of by the database engine.

When would I NOT want to use a View Index?

You obviously cannot use a View Index if you need to include syntax in the view definition that is not allowed. It seems to me that Top, Min, Max, Count, using another view, union, subqueiries and outer joins are serious restrictions that would disqualify a large number of views that I might want to optimize using the View Index.

Storage may also be a major consideration as the data in the view is physically and permanently stored not only in its base table, but in the clustered index of the View Index. Effectively, the data is stored twice, once in its base table and once in the clustered index of the Indexed View.

Also, On-Line Transaction Processing systems (OLTP) will actually suffer performance loss if you try to use View Indexes. Databases with frequent inserts, updates, deletes suffer as these commands must not only process the table, but any associated Indexed Views that the base table is participating in. Also, views that are simply subsets of rows or columns with no aggregation or computation provide no benefit over a standard SQL view or a T-SQL command directly against the base tables. This additional overhead to update the data in the clustered index of the view I believe is the reason that the clustered index must be unique for an Indexed view. It uses this unique value to quickly update the appropriate record in the Indexed View. Without a unique index, the processing for updating the Indexed View records could be unacceptably long.

What are the performance benefits?

As I indicated earlier, I experienced query times 3 times quicker using the Indexed Views over the same query not using the Indexed Views on the sample data in the NorthWind database. With a much bigger data set and with the same database objects defined, I got query times as much as 50 times faster. Microsoft has reported performance improvements of 10 to 100 times with applications that access indexed views instead of base tables. I also experimented with using other queries that did not directly reference the Indexed View and got similar performance gains when the optimizer selected the Indexed View over other possible execution plans.

Summary

As you can see, even with its restrictions, the View Index is a powerful new tool in the SQL Server Developer’s toolbox. Because the optimizer can use a View Index, you won’t even have to change your existing T-SQL to take advantage of the performance benefits of the View Index. So take into consideration the information above when evaluating whether a View Index is right for your application. 
By Doug Carpenter on 18 October 2000
Found on: this link

SEO là gì?

September 1, 2008

Trong xã hội ảo, thương hiệu không quan trọng bằng việc xuất hiện đầu tiên trong kết quả tìm kiếm của các bộ máy tìm kiếm, đặc biệt là Google.

Nhu cầu quảng bá trên các web tìm kiếm

Thống kê cho thấy 80% số người dùng Internet thường xuyên sử dụng công cụ tìm kiếm.

Đây là các chỉ số giúp cho quảng cáo trực tuyến, đặc biệt là quảng cáo qua công cụ tìm kiếm, ngày càng lấn sân những loại hình quảng cáo truyền thống trên thế giới. Tại Việt Nam, theo khảo sát của Công ty cổ phần kết nối truyền thông Việt Nam (VinaLink), có khoảng 73% người dùng Internet thường xuyên truy cập vào trang web tìm kiếm Google so với 13% truy cập vào trang Yahoo.

Doanh nghiệp ở Việt Nam cũng đã nhận ra điều này và mua quảng cáo của các công cụ tìm kiếm ngày càng nhiều, đặc biệt là dịch vụ quảng cáo Adwords của Google. Dễ dàng kiểm chứng điều này bằng cách vào Google, gõ một số từ khóa phổ biến như “sách”, “du lịch” hay “nha khoa” thì ngay bên phải trang web tìm kiếm sẽ thấy xuất hiện các nhà cung cấp liên quan.

Bên cạnh việc sử dụng dịch vụ quảng cáo trên các bộ máy tìm kiếm như Adwords của Google hay Yahoo Marketing của Yahoo, nhiều doanh nghiệp còn có nhu cầu nữa là đứng trong tốp đầu các trang liệt kê kết quả tìm kiếm của công cụ tìm kiếm. Giới chuyên làm quảng bá trang web gọi đó là dịch vụ SEO (Search engine optimization – SEO).

SEO là quy trình tối ưu hóa tìm kiếm web nhằm tăng lượng truy cập đến trang web từ các bộ máy tìm kiếm. Mục tiêu của SEO là đưa trang web lên hàng đầu trong kết quả tìm kiếm theo một số từ khóa cụ thể. Ví dụ, với các công ty du lịch lữ hành, mục tiêu làm SEO là khi khách hàng tra từ khóa liên quan đến du lịch như Vietnam travel thì trang web của công ty đó phải xuất hiện trong top đầu của kết quả tìm kiếm. Tuy nhiên, SEO không giới hạn trong tìm kiếm text mà còn trong tìm kiếm ảnh, sách, nhạc và các tìm kiếm ngành dọc khác.

Theo một số doanh nghiệp, thị trường tư vấn SEO tại Việt Nam vẫn dừng ở giai đoạn đầu nhưng tương lai sẽ phát triển nhanh cùng với bước tiến mạnh mẽ của dịch vụ trực tuyến.

Ông Hà Tuấn Anh, Giám đốc Vinalink cho biết công ty bắt tay làm dịch vụ SEO từ 2002. Ban đầu, khách hàng chủ yếu là công ty du lịch lữ hành, xuất khẩu thủ công mỹ nghệ và đá quý hoặc người làm quản trị web. Nhưng hiện nay, do lượng người dùng Internet và số trang web ngày càng nhiều, mức cạnh tranh cao nên SEO cũng được quan tâm hơn. Nhiều công ty kinh doanh máy tính, các văn phòng luật, nha khoa, thám tử, dịch vụ diệt mối, côn trùng…, thậm chí có một trang web của ủy ban nhân dân tỉnh đã tìm đến SEO. Thương mại điện tử cũng bắt đầu có khách hàng, nhất là giao dịch B2B (doanh nghiệp với doanh nghiệp). Gần đây, mỗi tháng VinaLink có thêm vài khách hàng, thời gian trước thì ít hơn nhiều.

Trên Internet, SEO hơn cả “thương hiệu”

Trong xã hội ảo, những trang web xuất hiện đầu tiên trong kết quả tìm kiếm có cơ hội thu hút được nhiều người tìm kiếm truy cập vào hơn. Vì vậy, nếu làm SEO tốt thì sẽ tăng được lượng người truy cập từ các trang web tìm kiếm.

Thậm chí, một chuyên gia quảng cáo web cho rằng: “Trên Internet, thương hiệu không là gì cả. Xuất hiện cao trên kết quả tìm kiếm mới quan trọng. Nếu công ty bạn không có mặt trong 3 trang đầu tiên của Google, bạn chả là gì cả”.

Thống kê trên thế giới, khoảng 70% người tìm kiếm không xem hết quá trang đầu, 97% không xem tới trang thứ 3. Ở Việt Nam, theo khảo sát của VinaLink, khoảng 50% lưu lượng vào các trang web do Google đem lại. Vì vậy, không ngạc nhiên khi dịch vụ SEO ở Việt Nam chủ yếu là trên Google. Hiện có khá nhiều công ty cung cấp dịch vụ SEO như Squangcao.com, Onboom, OntopRank hay VinaLink.

Chi phí làm dịch vụ SEO trên Google khá tốn kém, từ vài triệu đồng đến vài chục triệu đồng tùy theo trang web và từ khóa. Có lĩnh vực như du lịch, hiện các công ty làm dịch vụ SEO không dám nhận làm SEO các từ khóa về du lịch, vì có quá nhiều trang web chen nhau ở một số từ khóa.

Theo ông Hà Tuấn Anh, những trang web đã duy trì lâu, có nhiều người truy cập và tốc độ cập nhật thông tin thường xuyên thì làm SEO rất nhanh, có hiệu quả sau khoảng 1 tuần. Còn những trang ít người truy cập, thông tin thiếu cập nhật thì có khi mất tới 1 – 2 năm mới tăng thứ hạng. Ngoài ra, việc tăng thứ hạng trong kết quả tìm kiếm cũng phụ thuộc vào tên miền. Nếu mục tiêu là quảng bá quốc tế thì nên chọn tên miền .com, còn nếu nhắm vào khách hàng trong nước thì ưu tiên tên miền .com.vn hay .vn.

Nguồn: ICT News


8 Premium One Line Css Tips

August 16, 2008

The best solutions are often the simplest. Here’s a list of 8 tips that contain only one css property.
1. Vertical centering with line-height

line-height:24px;

When you have a container with fixed height you can use line-height property to vertically center the content.
Take a look at this demo.
2. Prevent oversized content to break fixed width floated layouts

#main{
overflow:hidden;
}

When oversized content (i.e. wide image) is placed in fixed width floated container, it may break the layout. To prevent that use this trick. It will hide a part of the content but at least your layout structure will remain intact.
I wrote an article about it a while back.
3. Prevent line breaks in links

a{
white-space:nowrap;
}

This little trick will prevent line breaks on your links. I recommend using this with long text to avoid having links break into 2 lines.
4. Always show Firefox scrollbar

html{
overflow:-moz-scrollbars-vertical;
}

Firefox hides vertical scrollbar by default. So, when you browse a site that have different page heights you notice a horizontal shift. This code will always display a scrollbar and prevent shifting.
5. Centering block elements horizontally

margin:0 auto;

For all modern browser this line of css is enough to horizontally center a block level element.
6. Remove vertical textarea scrollbar in IE

textarea{
overflow:auto;
}

Textareas in IE have vertical scrollbar visible by default. If you want those removed (I know I do) use this line.
7. Force page breaks when printing your document

h2{
page-break-before:always;
}

With this line of code you can control places where you want your pages to break when printing a document.
8. Remove active link borders

a:active, a:focus{
outline:none;
}

Originally found here, this will remove dotted outline from focused or active links.


Cài đặt Windows Server 2003 và tạo server dự phòng

August 12, 2008

Cài liệu quản trị mạng Server 2003 như chi tiết cách cài đặt, tạo thêm 1 Server đồng hành để phòng hờ trường hợp Server chính bị trục trặc, tạo domain, gia nhập máy con vào domain, remote destop conection {từ máy con truy xuất dữ liệu vào máy server}, cài đặt thông số ADSL router vào máy server, tắt 1 máy con đang hoạt động ngay tức thời.

  • Nếu gia tăng thêm số lượng máy con vào domain thì gắn thêm Switch như thế nào để đảm bảo truyền dữ liệu và truy cập internet được tốt nhất
  • Số lượng máy bao nhiêu thì nên dùng đường truyền ADSL với tốc độ như thế nào (ví dụ khoảng 50 máy, 70 máy, hơn 100 máy).
  1. Chi tiết cách cài đặt domain và cài đặt thông số ADSL router vào máy server:
    Trước tiên bạn phải Cài đặt Windows Server 2003
    Tiến hành các bước sau trên Computer sẽ đóng vai trò Domain Controller

    1. Đưa đĩa CD cài đặt vào CD-ROM, khởi động lại Computer. Cho phép boot từ đĩa CD
    2. Chương trình Windows setup bằt đầu load những Files phục vụ cho việc cài đặt. Nhấn Enter khi mà hình Welcome to Setup xuất hiện
    3. Đọc những điều khoản về License trên Windows Licensing Agreement , sau đó nhấn F8 để đồng ý với các điều khoản quy định của MS
    4. Trên Windows Server 2003, xuất hiện màn hình tạo các phân vùng Partition trên đĩa cứng, trước hết tạo Partition dùng cho việc cài đặt Hệ Điều hành. Nhấn ENTER.
    5. Trên Windows Server 2003, chọn Format the partition using the NTFS file system Nhấn ENTER.
    6. Chương trình Windows Setup tiến hành định dạng (format) đĩa cứng, sẽ chờ ít phút cho tiến trình này hoàn tất
    7. Computer sẽ tự Restart khi tiến trình copy File vào đĩa cứng hoàn tất
    8. Computer sẽ restart lại và boot giao diện đồ họa. Click Next trên trang Regional and Language Options
    9. Trên trang Personalize Your Software, điền Tên và Tổ chức của Bạn
      Ví dụ : Name: Server 2003
      Organization: Bao Tuoi Tre
    10. Trên trang Product Key điền vào 25 chữ số của Product Key mà bạn có và click Next.
    11. Trên trang Licensing Modes chọn đúng option được áp dụng cho version Windows Server 2003  mà bạn cài đặt. Nếu cài đặt Licence ở chế độ per server licensing, hãy đưa vào số connections mà bạn đã có License. Click Next.
    12. Trên trang Computer Name và Administrator Password điền tên của Computer ví dụ Server2003, tên này được điền vào Computer Name text box. Điền tiếp vào mục Administrator password và xác nhận lại password tại mục Confirm password (ghi nhớ lại password administrator cẩn thận, nếu không thì bạn cũng không thể log-on vào Server cho các hoạt động tiếp theo). Click Next.
    13. Trên trang Date and Time Settings xác lập chính xác Ngày, giờ và múi giờ Việt Nam (nếu các bạn ở Việt Nam), lưu ý time zone là GMT + 7
    14. Click Next.
    15. Trên trang Networking Settings, chọn Custom settings option.
    16. Trên trang Network Components, chọn Internet Protocol (TCP/IP) entry trong
    17. Components và click Properties.
    18. Trong Internet Protocol (TCP/IP) Properties dialog box, xác lập các thông số sau:
    19. IP address: 10.0.0.2.
    20. Subnet mask: 255.255.255.0.
    21. Default gateway: 10.0.0.1 (chú ý Default Gateway 10.0.0.1 này cũng là IP address của Card Ethernet cua Router ADSL).
    22. Preferred DNS server: 10.0.0.2 và Additional DNS server la địa chỉ mà ISP đã cung cấp cho ADSL Router, ví dụ : 203.162.4.1
    23. Click OK trong Advanced TCP/IP Settings dialog box.
    24. Click OK trong Internet Protocol (TCP/IP) Properties dialog box.
    25. Click Next trên trang Networking Components.
    26. Chấp nhận lựa chọn mặc định môi trường Network là Workgroup (chúng ta sẽ tạo môi trường Domain sau, thăng cấp (promote) máy này trở thành một Domain controller và cũng là thành viên của Domain. Click Next.
    27. Tiến trình cài đặt được tiếp tục và khi Finish, Computer sẽ tự khởi động lại
    28. Log-on lần đầu tiên vào Windows Server 2003 dùng password mà chúng ta đã tạo cho tài khoản Administrator trong quá trình Setup.
    29. Xuất hiện đầu tiên trên màn hình là trang Manage Your Server, bạn nên check vào “Don’t display this page at logon checkbox” và đóng cửa sổ Window lại.

    Bước kế tiếp là quá trình cài đặt và cấu hình DNS trước khi chạy tiện ích dcpromo

    Bước kế tiếp là cài đặt Domain Naming System (DNS) server trên chính server này. Điều này là cần thiết vì Active Directory Service hoạt động trên Domain Controller, kiểm soát toàn Domain yêu cầu phải có DNS server service phục vụ cho nhu cầu truy vấn tên như hostname, đăng kí các record (A, PTR, SRV records v.v..). Chúng ta sẽ cài DNS server và sau đó sẽ nâng vai trò Computer này lên thành một Domain Controller, và DNS server này sẽ phục vụ truy vấn cho toàn Domain.

  2. Tiến hành các bước sau để cài đặt DNS server:

    1. Click Start, Control Panel. Click Add or Remove Programs.
    2. Trong Add or Remove Programs, click Add/Remove Windows Components
    3. Trong Windows Components, xem qua danh sách Components và click Networking Services entry. Click Details.
    4. Check vào Domain Name System (DNS) checkbox và click OK.
    5. Click Next trong Windows Components.
    6. Click Finish trên Completing the Windows Components Wizard.
    7. Đóng Add or Remove Programs

    DNS server đã được cài đặt, Admin cần đưa vào DNS Server các thông số cụ thể phục vụ cho hoạt động truy vấn tên, cụ thể là sẽ tạo ra hai vùng Forward và Reverse lookup zones.

  3. Tiến hành các bước sau để cấu hình DNS server:
    1. Click Start và sau đó click Administrative Tools. Click DNS.
    2. Trong bảng làm việc của DNS (DNS console), mở rộng server name (Server2003 ), sau đó click trên Reverse Lookup Zones. Right click trên Reverse Lookup Zones và click New Zone.
    3. Click Next trên Welcome to the New Zone Wizard.
    4. Trên Zone Type , chọn Primary zone option và click Next.
    5. Trên Reverse Lookup Zone Name page, chọn Network ID option và Enter 10.0.0 vào text box. Click Next.
    6. Chấp nhận chọn lựa mặc định trên Zone File page, và click Next.
    7. Trên Dynamic Update page, chọn Allow both nonsecure and secure dynamic updates option. Click Next.
    8. Click Finish trên Completing the New Zone Wizard page.
  4. Kế tiếp chúng ta tạo Forward lookup zone cho Domain mà Computer này sẽ là Domain Controller. Tiến hành các bước sau:

    1. Right click Forward Lookup Zone và click New Zone.
    2. Click Next trên Welcome to the New Zone Wizard page.
    3. Trên Zone Type page, chọn Primary zone option và click Next.
    4. Trên Zone Name page, điền tên của forward lookup zone trong Zone name text box. Trong ví dụ này tên của zone là quantrimang.com, trùng với tên của Domain sẽ tạo sau này. Đưa quantrimang.com vào text box. Click Next.
    5. Chấp nhận các xác lập mặc định trên Zone File page và click Next.
    6. Trên Dynamic Update page, chọn Allow both nonsecure and secure dynamic updates. Click Next.
    7. Click Finish trên Completing the New Zone Wizard page.
    8. Mở rộng Forward Lookup Zones và click vào MSFirewall.org zone. Right click trên quantrimang.com và Click New Host (A).
    9. - Trong New Host dialog box, điền vào chính xác Server2003 trong Name (uses parent domain name if blank) text box.
      - Trong IP address text box, điền vào 10.0.0.2. Check vào “Create associated pointer (PTR) record checkbox”.
      - Click Add Host.
      - Click OK trong DNS dialog box thông báo rằng (A) Record đã được tạo xong.
      - Click Done trong New Host text box.
    10. Right click trên quantrimang.com forward lookup zone và click Properties. Click Name Servers tab. Click exchange2003be entry và click Edit.
    11. Trong Server fully qualified domain name (FQDN) text box, điền vào tên đầy đủ của Domain controller computer là Server2003. quantrimang.com. Click Resolve. Sẽ nhận thấy, IP address của Server xuất hiện trong IP address list. Click OK.
    12. Click Apply và sau đó click OK trên quantrimang.com Properties dialog box.
    13. Right click trên DNS server name Server2003, chọn All Tasks. Click Restart.
    14. Close DNS console.

    Giờ đây Computer này đã sẵn sàng để nâng vai trò lên Thành một Domain controller trong Domain quantrimang.com

  5. Tiến hành các bước sau để tạo Domain và nâng server này thành Domain Controller đầu tiên của Domain
    Cài đặt First Domain Controller

    1. Click Start và click Run .
    2. Trong Run dialog box, đánh lệnh dcpromo trong Open text box và click OK.
    3. Click Next trên Welcome to the Active Directory Installation Wizard page.
    4. Click Next trên Operating System Compatibility page.
    5. Trên Domain Controller Type page, chọn Domain controller for a new domain option và click Next.
    6. Trên Create New Domain page, chọn Domain in a new forest option và click Next.
    7. Trên New Domain Name page, điền tên đầy đủ của Domain (Full DNS name) quantrimang.com text box và click Next.
    8. Trên NetBIOS Domain Name page (NetBIOS name của Domain nhằm support cho các Windows OS- như các dòng Windows NT và WINDOWS 9x đời cũ, khi các Client này muốn giao dịch với Domain), chấp nhận NetBIOS name mặc định Trong ví dụ này là tuoitre. Click Next.
    9. Chấp nhận các xác lập mặc định trên Database and Log Folders page và click Next.
    10. Trên Shared System Volume page, chấp nhận vị trí lưu trữ mặc định và click Next.
    11. Trên DNS Registration Diagnostics page, chọn I will correct the problem later by configuring DNS manually (Advanced). Click Next.
    12. Trên Permissions page, chọn Permissions compatible only with Windows 2000 or Windows Server 2003 operating system option. Click Next.
    13. Trên Directory Services Restore Mode Administrator Password page (chế độ phục hồi cho Domain Controller khi DC này gặp phải sự cố, Khi DC offline, vào chế độ troubleshoot này bằng cách Restart Computer, chọn F8), điền vào Restore Mode Password và sau đó Confirm password. (Các Admin không nên nhầm lẫn Password ở chế độ này với Domain Administrator Password, điều khiển hoạt động của DCs hoặc Domain). Click Next.
    14. Trên Summary page, click Next.
    15. Bây giờ là lúc Computer cần Restart để các thông số vừa cài đặt Active
    16. Click Finish trên Completing the Active Directory Installation Wizard page, hoàn thành việc cài đặt.
    17. Click Restart Now trên Active Directory Installation Wizard page.
    18. Log-on vào Domain Controller dùng tài khoản Administrator.
  6. Tạo thêm 1 Server đồng hành để phòng hờ trường hợp Server chính bị trục trặc:

    1. - Cấu hình địa chỉ Server như sau : IP address: 10.0.0.3. Subnet mask: 255.255.255.0. Default gateway: 10.0.0.1 (chú ý Default Gateway 10.0.0.1 này cũng là IP address của Card Ethernet cua Router ADSL).
      - Preferred DNS server: 10.0.0.2 và Additional DNS server la địa chỉ mà ISP đã cung cấp cho ADSL Router, ví dụ : 203.162.4.1
      - Sau đó Right click My Computer, click Properties.
    2. Trong System Properties dialog box, click Network Identification tab. Click Properties .
    3. Trong Changes dialog box, click More.
    4. Trong Primary DNS suffix of this computer text box, điền vào domain name là tên của domain (quantrimang.com) chứa Computer này. Nếu Computer không là thành viên của Domain thì text box sẽ để trống.
      Chú ý: Change primary DNS suffix when domain embership changes được enabled theo mặc định. Trong ví dụ hiện tại Computer không phải là thành viên của Domain. Cancel tất cả dialog boxes vừa xuất hiện và không cấu hình primary domain name tại thời điểm này.
    5. Restart lại Server
    6. Thực hiện tương tự như bước 2, trong Changes, chọn Domain Text box và nhập vào: quantrimang.com. Nhập user và password tương ứng của user administrator.
    7. Restart lại server và chọn logon vào domain.
  7. Bước kế tiếp tiến hành install Additional domain Controller

    1. Click Start và click Run .
    2. Trong Run dialog box, đánh lệnh dcpromo trong Open text box và click OK.
    3. Click Next trên Welcome to the Active Directory Installation Wizard page.
    4. Click Next trên Operating System Compatibility page.
    5. Trên Domain Controller Type page, chọn Additional Domain controller for an existing domain option và click Next.
    6. Nhập user administrator và password sau đo trong text box domain nhập quantrimang.com
    7. Trên NetBIOS Domain Name page (NetBIOS name của Domain nhằm support cho các Windows OS- như các dòng Windows NT và WINDOWS 9x đời cũ, khi các Client này muốn giao dịch với Domain), chấp nhận NetBIOS name mặc định Trong ví dụ này là tuoitre. Click Next.
    8. Chấp nhận các xác lập mặc định trên Database and Log Folders page và click Next.
    9. Trên Shared System Volume page, chấp nhận vị trí lưu trữ mặc định và click Next.
    10. Trên DNS Registration Diagnostics page, chọn I will correct the problem later by configuring DNS manually (Advanced). Click Next.
    11. Trên Permissions page, chọn Permissions compatible only with Windows 2000 or Windows Server 2003 operating system option. Click Next.
    12. Trên Directory Services Restore Mode Administrator Password page (chế độ phục hồi cho Domain Controller khi DC này gặp phải sự cố, Khi DC offline, vào chế độ troubleshoot này bằng cách Restart Computer, chọn F8), điền vào Restore Mode Password và sau đó Confirm password. (Các Admin không nên nhầm lẫn Password ở chế độ này với Domain Administrator Password, điều khiển hoạt động của DCs hoặc Domain). Click Next.
    13. Trên Summary page, click Next.
    14. Bây giờ là lúc Computer cần Restart để các thông số vừa cài đặt Active
    15. Click Finish trên Completing the Active Directory Installation Wizard page, hoàn thành việc cài đặt.
    16. Click Restart Now trên Active Directory Installation Wizard page.
    17. Log-on vào Domain Controller dùng tài khoản Administrator.
  8. Gia nhập máy con vào domain:

    1. Mở Active Directory User and Computer sau đó tạo các domain user tương ứng
    2. Logon vào máy con, và thực thi tương tự như quá trình Tạo thêm 1 Server đồng hành để phòng hờ trường hợp Server chính bị trục trặc.
    3. Logon vào domain với domain user đã được tạo ra.
  9. Remote destop conection va shutdown máy con từ xa:
    Để remote máy con và máy chủ chúng ta làm như sau:

    1. Trong computer – properties – remote – chọn enable remote desktop on this computer
    2. Sau đó chúng ta có thể logon vào các máy tính đã cho phép remote sử dụng công cụ Remote Desktop Connnection. Nhập địa chỉ IP của máy chủ và máy con và sử dụng user administrator để remote. Sau khi remote thành công chúng ta có thể shutdown máy tính từ xa 1 cách dễ dàng, thông qua tab shutdown trong start menu.
    3. - Nếu gia tăng thêm số lượng máy con vào domain thì gắn thêm Switch như thế nào để đảm bảo truyền dữ liệu và truy cập internet được tốt nhất?
      - Khi bạn thêm máy con vào domain thì bạn cần thêm các switch tương ứng, vì mỗi máy cần một port trên swith. Ví dụ bạn có 40 máy thì bạn phải có 2 switch 24 port để đáp ứng cho 40 máy tính kết nối vào.
    4. - Số lượng máy và đường truyền ADSL với tốc độ thích hợp.
      - Nếu như có nhiều máy trong domain thì bạn chỉ cần thêm switch, còn đường truyền ADSL thì phụ thuộc vào từng nhà cung cấp dịch vụ, bạn có thể chọn ADSL của FPT, Viettel, VDC… Ngoài ra nếu số lượng máy tính nhiều bạn nên chọn gói ADSL có tốc độ cao nhất. để có thể cho phép các user trong mạng duyệt web, download và upload một cách dễ dàng.

TAM TRUNG (MCSE, MCDBA, Giảng viên SaigonCTT)


Add to Favorites (IE) / Bookmark (Firefox)

August 10, 2008

I can only get i work in FireFox and Internet Explorer

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>Untitled Page</title>
    <script type="text/javascript">
        function AddToFav(url, title)
        {
            if (window.sidebar) // FF
            {
		        window.sidebar.addPanel(title, url,"");
	        }
	        else if( window.external ) // IE
	        {
		        window.external.AddFavorite(url, title);
		    }
	        else if(window.opera && window.print) // Opera
	        {
		        var el = document.createElement('a');
                el.setAttribute('href',url);
                el.setAttribute('title',title);
                el.setAttribute('rel','sidebar');
                el.click();
		    }
        }
    </script>
</head>
<body>
<a href="javascript:AddToFav('http://augsev.wordpress.com', 'AugSev Blog')" title="bookmark">Bookmark</a>
</body>
</html>

yahoo messenger status images

August 2, 2008
http://mail.opi.yahoo.com/online?u=auguseve&m=a&t=0
offline: auguseve is NOT ONLINE
online: auguseve is ONLINE
http://mail.opi.yahoo.com/online?u=auguseve&m=a&t=1
online: 01
offline: 00
http://mail.opi.yahoo.com/online?u=auguseve&m=g&t=0

or http://mail.opi.yahoo.com/online?u=auguseve
http://mail.opi.yahoo.com/online?u=auguseve&m=g&t=1
http://mail.opi.yahoo.com/online?u=auguseve&m=g&t=2
http://mail.opi.yahoo.com/online?u=auguseve&m=g&t=3
http://mail.opi.yahoo.com/online?u=auguseve&m=g&t=4
http://mail.opi.yahoo.com/online?u=auguseve&m=g&t=5
http://mail.opi.yahoo.com/online?u=auguseve&m=g&t=6
http://mail.opi.yahoo.com/online?u=auguseve&m=g&t=7
http://mail.opi.yahoo.com/online?u=auguseve&m=g&t=8
http://mail.opi.yahoo.com/online?u=auguseve&m=g&t=9
http://mail.opi.yahoo.com/online?u=auguseve&m=g&t=10
http://mail.opi.yahoo.com/online?u=auguseve&m=g&t=11
http://mail.opi.yahoo.com/online?u=auguseve&m=g&t=12
http://mail.opi.yahoo.com/online?u=auguseve&m=g&t=13
http://mail.opi.yahoo.com/online?u=auguseve&m=g&t=14
http://mail.opi.yahoo.com/online?u=auguseve&m=g&t=15
http://mail.opi.yahoo.com/online?u=auguseve&m=g&t=16