Thứ Tư, 19 tháng 7, 2017

[ASP.NET] A potentially dangerous Request.Form value was detected from the client

Lỗi này không phải do phía server mà do phía code xử lý, cụ thể lỗi xuất hiện khi post dữ liệu từ form có cấu trúc HTML lên.  đây là 1 bug trong lập trình mà hacker có thể lợi dụng để chèn code/script vào site quý khách với ý đồ xấu do đó mặc định ASP.NET sẽ không cho post dữ liệu như vậy và xuất hiện lỗi trên.

Tham khảo thông tin của bug trên tại link sau :  https://docs.microsoft.com/en-us/aspnet/whitepapers/request-validation 

Có thể tắt tính năng validate của ASP.NET để bỏ qua lỗi này, tuy nhiên việc này microsoft không khuyến cáo vì lý do nêu trên

Tham khảo disable validate trong website : https://msdn.microsoft.com/en-us/library/hh882339(v=vs.110).aspx

Chủ Nhật, 18 tháng 6, 2017

[ASP.NET][IIS] The .Net Framework Data Providers require Microsoft Data Access Components(MDAC). Please install Microsoft Data Access Components(MDAC) version 2.6 or later

Error :

The .Net Framework Data Providers require Microsoft Data Access Components(MDAC).  Please install Microsoft Data Access Components(MDAC) version 2.6 or later


The reason for this error is that the application pool is trying to read a registry key from the HKey_Current_User hive which isn't always loaded. The solution is as follow:
  1. Open IIS management console
  2. Click on "Application Pools"
  3. Right-click the pool for your web site and select "Advanced Settings"
  4. Change the setting "Load User Profile" to True

Thứ Năm, 4 tháng 5, 2017

[MSSQL] Find out CPU usages of all different SQL Server Objects

In SQL Server Management Studio run the "Performance - Top Queries By Total CPU Time" report.


In this post, I provide you one script to find out CPU usages of all different SQL Server Objects.
This script is very important for DBA when DBA monitoring CPU usages.
Below is a script:

http://www.dbrnd.com/2015/06/sql-server-cpu-usage-per-different-objects/







Measure CPU Usage Per Database :

 WITH cte as ( SELECT SDEPA.DatabaseID , SUM (SDEQS.total_worker_time) AS CPUTimeInMiliSeconds FROM sys.dm_exec_query_stats SDEQS CROSS APPLY (SELECT CAST(value as int) AS [DatabaseID] FROM sys.dm_exec_plan_attributes(SDEQS.plan_handle) WHERE attribute = N'dbid') SDEPA GROUP BY SDEPA.DatabaseID) SELECT COALESCE(DB_NAME(DatabaseID), '{Overhead Processes}') as [Database] , CAST ([CPUTimeInMiliSeconds] * 1.0 / SUM ([CPUTimeInMiliSeconds]) OVER () * 100.0 as DECIMAL(6, 3)) AS [CPUTime%] FROM cte ORDER BY CAST ([CPUTimeInMiliSeconds] * 1.0 / SUM ([CPUTimeInMiliSeconds]) OVER () * 100.0 as DECIMAL(6, 3)) DESC;


Thống kê top query trên database cụ thể:

SELECT TOP 10 SUBSTRING(qt.TEXT, (qs.statement_start_offset/2)+1,
((CASE qs.statement_end_offset
WHEN -1 THEN DATALENGTH(qt.TEXT)
ELSE qs.statement_end_offset
END - qs.statement_start_offset)/2)+1),
qs.execution_count,
qs.total_logical_reads, qs.last_logical_reads,
qs.total_logical_writes, qs.last_logical_writes,
qs.total_worker_time,
qs.last_worker_time,
qs.total_elapsed_time/1000000 total_elapsed_time_in_S,
qs.last_elapsed_time/1000000 last_elapsed_time_in_S,
qs.last_execution_time,
qp.query_plan,
[DB] = DB_NAME(qt.[dbid])
FROM sys.dm_exec_query_stats qs
CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) qt
CROSS APPLY sys.dm_exec_query_plan(qs.plan_handle) qp
--ORDER BY qs.total_logical_reads DESC -- logical reads
--ORDER BY qs.total_logical_writes DESC -- logical writes
where DB_NAME(qt.[dbid]) = 'db_name'
ORDER BY qs.total_worker_time DESC -- CPU time

Thứ Năm, 8 tháng 12, 2016

[Cpanel] Unexpected condition from IMAP server, closed or corrupt connection to IMAP. Possible mailbox corruption.

Đối với lỗi "Unexpected condition from IMAP server, closed or corrupt connection to IMAP. Possible mailbox corruption." khi sử dụng IMAP hoặc Webmail, các bạn ssh và cd vào thư muc mail của hosting

cd /home/user/mail/domain
Eg: cd /home/a406/mail/atwo.com.vn
và chay lệnh rename file dovecot.index thành dovecot.index.backup
find . -type f -name 'dovecot.index' -execdir mv {} {}_backup ';'


Một số trường hợp user không có dovecot.index mà có dovecot.index.cache nên sửa lại lệnh như bên dưới 
find . -type f -name 'dovecot.index.cache' -execdir mv {} {}_backup ';'

Thứ Tư, 7 tháng 12, 2016

[ASP.NET] The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use and max pool size was reached.

Server Error in '/' Application. 

Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use and max pool size was reached. 


 => Lỗi này liên quan tới kết nối database quá nhiều. Max Pool Size trong connection string mặc định là 100, có thể set cao hơn để theo dõi. Tuy nhiên khuyến cáo kiểm tra code đóng mở kêt nối .


Server=myAddress:myPortNumber;Database=myDataBase;UID=myUsername;PWD=myPassword; Max Pool Size=100;Min Pool Size=10;

https://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.connectionstring(v=vs.110).aspx

Thứ Năm, 1 tháng 12, 2016

[MSSQL] List Database (expand databse) in SSMS Slow

https://social.msdn.microsoft.com/Forums/sqlserver/en-US/99bbcb47-d4b5-4ec0-9e91-b1a23a655844/ssms-2012-extremely-slow-expanding-databases?forum=sqltools

lý do có nhiều database đang set auto_close = on 
=> xử lý là set thuộc tính database  auto_close = off

SELECT 'Alter Database [' +name+'] set AUTO_CLOSE OFF'
FROM master.sys.databases AS dtb 
WHERE is_auto_close_on = 1
ORDER BY name

=> copy lệnh run trên query mới

Used this script to find those databases: 
SELECT name, is_auto_close_on, is_auto_shrink_on FROM master.sys.databases AS dtb 
WHERE is_auto_close_on = 1 OR is_auto_shrink_on = 1
ORDER BY name

giải thích thuộc tính  auto_close

 According to Books Online:
When set to ON, the database is shut down cleanly and its resources are freed after the last user exits. The database automatically reopens when a user tries to use the database again.

    When set to OFF, the database remains open after the last user exits

AjaxToolkit IIS7 Asp.Net 4.0 - Sys is not defined - scriptsource.axd

<handlers>
    <add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
    <add name="ISAPI-4.0" path="*.axd" verb="*" modules="IsapiModule" scriptProcessor="C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" resourceType="Unspecified" requireAccess="Script" preCondition="classicMode,runtimeVersionv4.0,bitness32" />
      <add name="ChartImageHandler" preCondition="integratedMode" verb="GET,HEAD,POST" path="ChartImg.axd" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
      <add name="PricelistHandler" verb="*" path="pricelist.csv" preCondition="integratedMode" type="NopSolutions.NopCommerce.BusinessLogic.ExportImport.PricelistHandler, Nop.BusinessLogic" />
</handlers>

Cần "ScriptResource.axd" va "*.axd"

Tham khao :
http://stackoverflow.com/questions/3822733/ajaxtoolkit-iis7-asp-net-4-0-sys-is-not-defined-handler-mapping-issue