Saturday, June 28, 2008
Web Hosting and Domain
Let me share few information regarding Web hosting and DNS.
Web Host -Means Server where our website resides.This always up and connected to internet to make our web site active.
Shared Hosting:- Most of the host provides Shared Hosting , as it is meaningless to use whole server for small website which does not have very heavy traffic or not a big application.
At that time on a on server more then one website is hosted and manged.shared hosting is widely used , it is very cost effective too.Shared hosting may not provide full access to server(it is depends upon service provider also).
Dedicated Server:- Dedicated Server means only one particuler website or particular user owns a server.Where Owner(Person who purchase Dedicated server from host ,yes your own pc also can be a dedicated server).Owner have full access of server ,freedom of installing new s/w ,uninstall s/w.
DNS:-Domain Name Server
As we all knows on back side web request is made through IPs.
DNS :- Map the IP(where our website hosted) and Domain Name (like www.google.com).
As defination you can say
DNS is the service which translates between Internet names and Internet addresses.
If you are working on a Windows machine, you can view your current IP address with the command WINIPCFG.EXE (IPCONFIG.EXE for Windows 2000/XP). On a UNIX machine, type nslookup along with a machine name (such as "nslookup www.howstuffworks.com") to display the IP address of the machine (use the command hostname to learn the name of your machine).
DNS is such a big thing so it can not be explained in a single post I will add more information about it.
Monday, June 23, 2008
Create Error log in Asp.net2.0
To maintain error log its good to have log for each day for a better review .
so here we will create log file everyday , and when file already exist will append error entry in to it.
For that create one class and write following method....
C#
public static void WriteError(string errorMessage)
{
try
{
//Specify path where log file to be created
string logfilePath = "~/Error/" + DateTime.Today.ToString("dd-mm-yy") + ".txt";
if (!File.Exists(System.Web.HttpContext.Current.Server.MapPath(logfilePath)))
{
File.Create(System.Web.HttpContext.Current.Server.MapPath(logfilePath)).Close();
}
using (StreamWriter wrtr = File.AppendText(System.Web.HttpContext.Current.Server.MapPath(logfilePath)))
{
wrtr.WriteLine("\r\nLog Entry : ");
wrtr.WriteLine("{0}", DateTime.Now.ToString(CultureInfo.InvariantCulture));
string err = "Error in: " + System.Web.HttpContext.Current.Request.Url.ToString() +
". Error Message:" + errorMessage;
wrtr.WriteLine(err);
wrtr.WriteLine("__________________________");
wrtr.Flush();
wrtr.Close();
}
}
catch (Exception ex)
{
WriteError(ex.Message);
}
}
Wednesday, June 18, 2008
Caching Concept
· Output Caching
· Fragment Caching
· Data Caching
· Cache Configuration
Output Caching
Performance is improved in an ASP.NET application by caching the rendered markup and serving the cached version of the markup until the cache expires. For example, if you have a page that displays user information from a database, caching will help improve performance by serving the page from memory instead of making a connection to the database on each page request.
You can cache a page by using the OutputCache API or simply by using the @outputcache directive. <%@ Page Language=”C#” %><%@ OutputCache Duration=”15” VaryByParam=”none” %>
The above cache directive will cache the page for 15 minutes.
So output caching is great for when you want to cache an entire page.
Fragment Caching
In many situations caching the entire page just isn’t going to cut it, for some reason or another you require specific sections of the page to display live information. One way to improve performance is to analyze your page and identify objects that require a substantial overhead to run. You can build a list of these objects that are expensive to run, and then cache them for a period of time using fragment caching.
For example, say your page default.aspx consists of three user controls. After looking over the code, you identified that you can cache one of them. You can simply add the caching directive to the top of the user control: <%@ Control %><%@ OutputCache Duration=”5” VaryByParam=”none” %>
Now keep in mind that the actual page that contains the control is not cached, only the user control. This means that the default.aspx page will be rendered each and every page request, but the user control is only ‘run’ every 15 minutes.
Data Caching
So we know that we can cache an entire page, or a fragment of a page by caching down to the user control level. Wouldn’t it be great if we could cache down to the object level? The good news is you can with ASP.NET Data caching.
The cache consists of a dictionary collection that is private to each application in memory. To insert items in the cache simply provide the collection with a unique name: Cache[“someKey”] = myObject;
Retrieving the object form the cache: myObject = (MyObject)Cache[“someKey”];
It is a good time to point out that you should always remember to check for null, and be sure to caste to your datatype.
Cache Configuration
If you are familiar with how caching worked in ASP.NET 1.0, you realize that managing all the cache directions for all your pages could potentially get out of hand. ASP.NET 2.0 introduces Cache Profiles that helps you centrally manage your cache. Cache settings can be inherited by your pages, and overridden if required by using the OutputCache directive.
The page directive looks pretty much the same, expect this time it references a cache profile that you defined in your web.config file.
Disable auto id’s when copying ASP.NET controls
For example, look at this code:
I took the first line, copied it and pasted it, and got the second line. It’s rare that I need to reference a validator in my CodeBehind.
Here is the option to disable this functionality in the Visual Studio options
(Tools->Options):

Simply uncheck the “Auto ID elements on paste in Source view” option.
Tuesday, June 17, 2008
Date/Time Conversions Using SQL Server
1 | select convert(varchar, getdate(), 1) | 01/07/08 |
2 | select convert(varchar, getdate(), 2) | 08.01.07 |
3 | select convert(varchar, getdate(), 3) | 07/01/08 |
4 | select convert(varchar, getdate(), 4) | 07.01.08 |
5 | select convert(varchar, getdate(), 5) | 07-01-08 |
6 | select convert(varchar, getdate(), 6) | 07 Jan 08 |
7 | select convert(varchar, getdate(), 7) | Jan 07, 08 |
10 | select convert(varchar, getdate(), 10) | 01-07-08 |
11 | select convert(varchar, getdate(), 11) | 08/01/07 |
101 | select convert(varchar, getdate(), 101) | 01/07/2008 |
102 | select convert(varchar, getdate(), 102) | 2008.01.07 |
103 | select convert(varchar, getdate(), 103) | 07/01/2008 |
104 | select convert(varchar, getdate(), 104) | 07.01.2008 |
105 | select convert(varchar, getdate(), 105) | 07-01-2008 |
106 | select convert(varchar, getdate(), 106) | 07 Jan 2008 |
107 | select convert(varchar, getdate(), 107) | Jan 07, 2008 |
110 | select convert(varchar, getdate(), 110) | 01-07-2008 |
111 | select convert(varchar, getdate(), 111) | 2008/01/07 |
TIME FORMATS | ||
8 or 108 | select convert(varchar, getdate(), 8) | 18:12:39 |
9 or 109 | select convert(varchar, getdate(), 9) | Jan 7 2008 6:13:02:140PM |
14 or 114 | select convert(varchar, getdate(), 14) | 18:13:21:093 |
You can also format the date or time without dividing characters, as well as concatenate the
date and time string:
Sample statement | Output |
select replace(convert(varchar, getdate(),101),'/','') | 01072008 |
select replace(convert(varchar, getdate(),101),'/','') + replace(convert(varchar, getdate(),108),':','') | 01072008181409 |
some sql commands
i. Create a script file by typing in the following line and save it as Message.sql
print 'Welcome today''s date is: ' + (convert(varchar, getdate()))
ii. Now goto command prompt and type: SQLCMD -i Message.sql
here, -i is the switch to specify the input file name.
2. Executing series of script files (sample)
Lets create couple of .sql files and then see how to execute them in order from command prompt. Please note that i am just showing an example here :) there are better methods of doing the same which I would explain later in the series!
i) Copy paste the below script and name it as 01TableCreation.sql
Create table tblTest
(
Sno int identity,
FName varchar(20)
)
Go
ii) Copy paste the below script and name it as 02InsertRecords.sql
Insert into tblTest (Fname) values ('a')
iii) Copy paste the below two lines and name it as test.bat
sqlcmd -U sa -P hotmail -S VADIVEL -d testbed -i "C:\Vadivel\SQL Related\Scripts\sqlcmd\01TableCreation.sql"
sqlcmd -U sa -P hotmail -S VADIVEL -d testbed -i "C:\Vadivel\SQL Related\Scripts\sqlcmd\02InsertRecords.sql"
here,
-U is SQL User name
-P is SQL Password
-S is the SQL Server name
-d is the SQL database name
-i is the input file to execute
iv) Execute the batch file
Now goto command prompt (Start >> Run >> cmd) and execute this batch file. The batch file would have created a table and inserted a record into it. If you want to deploy some DB scripts on a remote box for which you don't have access from Mgmt Studio you can follow this batch file route. So that the ppl who are having access to that SQL box can just run this batch file (after changing the values of the different switches, if need be)
Setting your default editor:
From my previous posts one can understand that it is possible to write SQL queries directly in command prompt with the help of SQLCMD utility.
Now let's assume we have typed a 'big' query and there is a typo there! Instead of going back and forth to edit it in command prompt won't it be easy if we are able to open the query in an editor and make the corrections there?
Yes its possible in SQLCMD. All we need to do is type ed and it will open up the last command/query in a text editor. FYI the default editor is Edit (the command line editor of MS DOS).
Step 1: Open up SQLCMD and connect to your SQLServer
Step 2: type any query of your choice
Step 3: type ed
Step 4: The query would have opened in the 'EDIT' utility of DOS. Once you are done with the change, save and exit from that.
Step 5: type go and press enter
Can I make 'ed' to open up notepad or any editor of my choice?
Yes it's possible.
Step 1: Open DOS prompt
Step 2: Type set sqlcmdeditor=notepad
Step 3: Open up SQLCMD and connect to your SQLServer
Step 4: type any query of your choice
Step 5: type ed
Step 6: The query would get opened in notepad. Once you are done with the change, save and exit from that.
Step 5: type go and press enter
Persist the Property Values in User Controls after postbacks.
private String strName
public String Name
{
get{return strName;}
set{strName= value;}
}
This
is wrong approach,It will lose your property values. whenever
you want to get the value of Name Property it will never get in
postbacks and you will always get the Null Exception.
Right Waypublic String NameYou will retain property value of user control during postback too.
{
get
{
Object obj = ViewState["Name"];
if(obj == null)
{
return null;
}
else
{
return (String)obj;
}
}
set
{
ViewState["Name"] = value;
}
}
