Log Writing and Sql Server Performance,How to disable back button in browser
Logging error as email using microsoft enterprise library
Most of us were worried after deploying the code in client UAT
environment and thinking of if any error occurred in our deployment when client
is doing testing.
When client is doing testing of code at the same time developer
will come to know about the error if any occurred through email. And we don't
have to wait for client to send errors in our code. What he/she has to do
is to augment web.config file only.
Web.config
<configuration>
<configSections>
<section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings,
Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true"/>
</configSections>
<loggingConfiguration name="" tracingEnabled="true" defaultCategory="General">
<listeners>
<add name="Email Trace Listener"
type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.EmailTraceListener,
Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35"
listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.EmailTraceListenerData,
Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35"
toAddress=xyz@gmail.com fromAddress=abc@gmail.com subjectLineStarter="Exception Occured" smtpServer="smtp.gmail.com" smtpPort="587"
formatter="Text Formatter" authenticationMode="UserNameAndPassword" useSSL="true" userName=abc@gmail.com password="*********"/>
type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FlatFileTraceListener,
Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35"
listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FlatFileTraceListenerData,
Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35"
fileName="trace.log"/>
</listeners>
<formatters>
<add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter,
Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35"
template="Timestamp: {timestamp}{newline}
Message: {message}{newline}
Category: {category}{newline}
Priority: {priority}{newline}
EventId: {eventid}{newline}
Severity: {severity}{newline}
Title:{title}{newline}
Machine: {localMachine}{newline}
App Domain: {localAppDomain}{newline}
ProcessId:
{localProcessId}{newline}
Process Name: {localProcessName}{newline}
Thread Name:
{threadName}{newline}
Win32 ThreadId:{win32ThreadId}{newline}
Extended Properties:
{dictionary({key} - {value}{newline})}" name="Text Formatter"/>
</formatters>
<categorySources>
<add switchValue="All" name="General">
<listeners>
<add name="Flat File Trace Listener"/>
<add name="Email Trace Listener"/>
</listeners>
</add>
</categorySources>
<specialSources>
<allEvents switchValue="All" name="All Events"/>
<notProcessed switchValue="All" name="Unprocessed Category"/>
<errors switchValue="All" name="Logging Errors & Warnings">
<listeners>
<add name="Flat File Trace Listener"/>
<add name="Email Trace Listener"/>
</listeners>
</errors>
</specialSources>
</loggingConfiguration>
<system.web>
<compilation debug="true"/>
</system.web>
</configuration>
Code for testing
try
{
throw new NullReferenceException("General null
reference");
}
catch (Exception ex)
{
LogEntry logEntry = new LogEntry();
logEntry.EventId = 100;
logEntry.Priority = 2;
logEntry.Message = "Informational message";
Logger.Write(ex.ToString() + logEntry);
}
class BaseClass
{
public BaseClass() { }
public BaseClass(Int32 parameter1) { }
public void Method1()
{
}
}
class SubClassSingleton : BaseClass
{
private SubClassSingleton() { }
private SubClassSingleton(Int32 parameter1) : base(parameter1) { }
private static SubClassSingleton _Instance = null;
public static SubClassSingleton Instance
{
get
{
if (_Instance == null)
{
_Instance = new SubClassSingleton();
}
return _Instance;
}
}
}
public static class Program
{
public static void Main()
{
var obj = SubClassSingleton.Instance;
obj.Method1();
}
}
SQL Server performance tips
1. Question Is the following SQL good or bad practice from a
performance perspective?
Searching for all rows of the year 2012:
CREATE INDEX tbl_idx ON tbl (date_column); SELECT text,
date_column FROM tbl WHERE datepart(yyyy, date_column) = 2012;
Given Answer
Good practice
There is no major improvement possible.
Explanation
Wrapping the table column in a function renders the index
useless for this query.
Write queries for continuous periods as explicit range
condition:
SELECT text, date_column FROM tbl WHERE date_column >=
CAST('2012-01-01' AS DATE) AND date_column < CAST('2013-01-01' AS DATE)
See also: Using DATE columns
Alternatively, but less desirable: Indexing Computed
Columns
2. Question Is the following SQL good or bad practice from a
performance perspective?
To find the most recent row
CREATE INDEX tbl_idx ON tbl (a, date_column); SELECT TOP 1 id,
date_column FROM tbl WHERE a = @a ORDER BY date_column DESC Given Answer
Bad practice
There is a major improvement possible.
Explanation
The statement can be executed as an indexed Top-N query. It
performs just like a B-Tree traversal only so it's very efficient. The trick is
that the index supports the where as well as the order by
clause. The database uses the index to find the last entry that matches
the where clause and takes it as result. There is no need to actually
perform a sort for the order by. See also: Querying Top-N
Rows in my Book SQL Performance Explained 3. Question Is the
following SQL good or bad practice from a performance perspective? Two queries,
searching by a common column: CREATE INDEX tbl_idx ON tbl (a, b); SELECT id, a,
b FROM tbl WHERE a = @a AND b = @b; SELECT id, a, b FROM tbl WHERE b = @b;
Given Answer Bad practice There is a major improvement possible. Explanation
The index covers the first query only, the second query cannot use the index to
the best extent possible. Changing the column order makes the index suitable
for both queries—without additional overhead. The index should therefore look
like this (columns exchanged): CREATE INDEX tbl_idx ON tbl (b, a); See
also: Multi-Column Indexes
4. Question Is the following SQL troublesome or bulletproof from
a performance perspective?
Searching within a string:
CREATE INDEX tbl_idx ON tbl (text); SELECT id, text FROM tbl
WHERE text LIKE '%TERM%';
Given Answer Troublesome There is high risk for performance
problems.
Explanation
LIKE expressions starting with a wildcard cannot use an
index to locate the matching entries. There is no simple way to tune such a
query. Use another access path if possible (e.g.,
additional where conditions). Otherwise consider using a full-text
index. See also: A visual explanation why
SQL's LIKE is slow
5. Question How will the change affect query performance?
Current situation, selecting about hundred rows out of a million
CREATE INDEX tbl_idx ON tbl (a, date_column); SELECT
date_column, count(*) FROM tbl WHERE a = @a GROUP BY date_column; Changed
query, selecting about ten rows out of a million SELECT date_column, count(*)
FROM tbl WHERE a = @a AND b = @b GROUP BY date_column;
Given Answer
The query will be much slower (impact >10%)
Explanation
The query will be much slower—regardless of the data. The
original query is executed as an index-only scan. It doesn't need to access the
table because the index covers the entire query—all referenced columns are
covered in the index. Although the additional where clause reduces
the number of returned rows, it requires a table access to fetch the
column B, which is not included in the index. That means that the new
query cannot run as an index-only scan; it must access the table as well. This
access is additional work that slows the query down—regardless whether the
final result is smaller due to this filter.
See also: Index-Only Scan in my book SQL
Performance Explained.
Call Private method from outside the class
Class test
{
private void fun()
{
// Method Logic
}
}
// Create object
test myObj = new test();
Type myType = myObj.GetType();
myType.InvokeMember("Fun",BindingFlags.InvokeMethod | BindingFlags.Instance | BindingFlags.NonPublic,null,myObj, null);
Enabling SSRS report caching.
I found a good article on SSRS reports caching. Anyone interested
can visit the following page:
How do disable
back button in browser
Generally there are cases when we want to disable back button in
browser. We have multiple options to disable back button in browser. Here are
the few:-
Java Script Way
We can use following java script to prevent back button:-
Java Script Way
We can use following java script to prevent back button:-
function
disableBackButton()
{
window.history.forward();
}
setTimeout("disableBackButton()",
0);
window.onunload=function()
{
null
};
HTML Way
We can also add Meta Tags in Head Section like this:-
If you want to do above approach through code. Here is the trick:-
HtmlMeta refreshMetaTag = new
HtmlMeta();
refreshMetaTag.HttpEquiv
= "Refresh";
refreshMetaTag.Content
= "90";
Page.Header.Controls.Add(refreshMetaTag);
ASP.Net Way
In ASP.Net we can use Cache to disable back button like this:-
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetExpires(DateTime.Now);
Microsoft Windows Azure - good videos to help learning the
technology!
I found good videos on microsoft windows azure technology.
Hope you would also find these useful, here is the link:
Comments
Post a Comment