Friday, March 30, 2007

user controls and asp.net 2.0

In asp.net 1.1 you could just call your user controls from a class and process the functions in the control that way...

Not happening in 2.0 !!

The 2.0 compiles pages on run and so, when you call a user control ...the class can not find the reference to the page...and so, that is not referenced correctly,...

I am still thinking of a better way of catching errors...if i find one, would make sure to post it here for future references...

ASP.NET Repeater vs. ASP.NET DataGrid

Personally, I find myself always using the Repeater or DataList as opposed to the DataGrid for all my custom reporting needs. And unless I need the horizontal display capabilities of the DataList, I always use the Repeater. Here are my problems with the DataGrid.

First, the DataGrid's built-in paging capabilities are horrible in terms of performance. It's built-in paging grabs all the rows from the database with each call and then only displays the necessary records. For any real-world application, you will need to turn off the built-in paging and create your own custom paging.

Second, it is near impossible to make the DataGrid look really good as it doesn't work with CSS nearly as well as the repeater. I find the problem is that the ASP.NET DataGrid applies its itemstyle and alternating itemstyles to the rows () as opposed to the cells ().

Third, the ASP.NET DataGrid requires the ViewState for its sorting capabilities. So, unless you want all the viewstate data to decrease the performance of your application, you will have to turn off its built-in sorting and create your own sorting methodology.

Unless you need the inline editing or edititemstyle and selecteditemstyle, which I don't use that often, forget the ASP.NET DataGrid. You will end up having to build our own sorting and paging mechanisms, so you might as well enjoy the flexibility of the ASP.NET Repeater.

Thursday, March 29, 2007

they didnt study

If you dont study be creative...check this out

THey didnt study

Top 10 Open-Source Software Alternatives for Poor College Students

Top 10 Open-Source Software Alternatives for Poor College Students





Beer money. Yeah, you know what I'm talking about: those sweet scented bills which all too often end up in your schools' bookstore cash register. Maybe you don't like beer. Maybe you like gadgets, or shrubs. It doesn't matter what you like (unless of course it is buying proprietary software, at which point you should stop reading this article and resume your career aspirations of becoming a jackass), all you have to like is money. And as a college student, I can't think of anything much more important. Ok, well, maybe some things, like a functioning DVR. Nevertheless, the truth is you can save a ton of cash on your college education by finding alternatives to expensive goods such as...



Replacing cds with mp3s.

Replacing food with Ramen Noodles.


Replacing steady girlfriends with whats her name.



But the real way you can save cash, is by replacing all that expensive proprietary software with open source solutions.




If you are a college student, you probably don't have a lot of extra money. Even if you do, why spend it if you didn't have to? Although many colleges and universities are now recommending that students bring a computer with them when they start college, most of them don't require a specific list of software. This is a blessing in disguise, because this is how you can save quite a bit of money.


There are a few schools, mainly engineering or art and design schools that recommend certain software, but guess what? There are low or no cost alternatives to almost all those expensive software programs.


You may have heard of open-source software (OSS) or free open-source software (FOSS) as some people call it. If you are not familiar with it, OSS is basically "any computer software whose source code is available under a license (or an agreement such as the public domain) that permits users to study, change and improve the software and to redistribute it in modified or unmodified form."


The following programs are some of the most common used by college students and their OSS alternatives or equivalents.





    1. Open Office---instead of Microsoft office, this alone could save you $200-300. And Open Office has equal if not better features, including a word processor, spreadsheet, multimedia presentation, drawing, database and more.

    2. Scribus--This desktop publisher can create documents such as term papers, research papers and more, for much less than Quark Xpress which costs $749.

    3. Maxima--Chances are you'll need some type of math software and for higher math and algebra, and why pay for Mathsoft when Maxima is free?

    4. BRL-CAD--If you are in an engineering or technical field, you know what TurboCad costs. This software developed by the US military Ballistics Research Laboratory, will cost you nothing.


    5. ClamWin--Developed to work with Windows, this antivirus program includes automatic downloads and programmable scanning, just like Norton Antivirus which costs $70

    6. Gimp--For GNU Image Manipulation Program, this program or its newer brother Gimpshop can equal Photoshop which retails at $650.

    7.  SciCraft--For statistics and data analysis, this software rivals SPSS.

    8.  Kompozer--Built on Nvu, this newer version can provide web design features like Dreamweaver which costs $400.


    9.  Banshee--For your music needs, instead of iTunes, why not check out this software with iPod synchronization as well as music players, burners and playlist features? 

    10.  Mozilla Seamonkey--Instead of Outlook, this software is an email service and internet browser with Chatzilla features. And you've got to love the name! Now that you know OSS is available, the choices are endless. There are literally hundreds of software programs out there for free or minimal costs. There is even a compilation called "Software for Starving Students" that includes over 40 programs, including games. This software is available for Mac OS X or Windows and includes OpenOffice and Firefox.



Just for fun, you might want to check out the Citrus Alarm Clock, which utilizes the media player on your computer to wake you at a set time. It even has features like fade-in or mute.




    And then there is iProcrastinate. Unfortunately, only available for Mac users at this point, this software allows students to enter classes, assignments and due dates and assign them priorities So you know exactly when you'd better get busy.


Circular File References and Other ASP.NET 2.0 / VS 2005 Conversion Issues

Circular File References and Other ASP.NET 2.0 / VS 2005 Conversion Issues

I’ve been plagued by “Circular file references are not allowed” errors on our converted ASP.NET 2.0 applications. This can happen when one ASCX control references another which contains a reference back to the first, but can also happen when there’s no obvious circular reference, such as when an ASCX control references another in a different directory that also contains other controls that reference back to the first one, or something like that (can you tell that I find this new build process slightly confusing?)… Point is, how do you get rid of it?

The docs mention this:

The solution for first type of circular reference is to create an abstract base class in the App_Code folder with one of the references, then remove the Reference directive from the associated web form or user control file. This will break the circular reference.

The second type of circular reference is a by-product of the ASP.NET compiler "batching" assemblies together for performance reasons. By default it will take the web forms and user controls in a folder and compile them into an assembly.

There are several ways to solve this issue, but we recommend moving the referenced pages (e.g. Pages2.aspx.vb and Pages3.aspx.vb) to their own folder. By default, the ASP.NET compiler will create a separate assembly containing these pages and the circular reference will be removed between Assembly A and B.

The circular references in our project weren’t completely obvious, and I’ve got bigger fish to fry right now than moving a bunch of files to get around this batch compilation issue. Fortunately, I found some good discussion here about how to deal with this. .

One additional note on batch=false -- this tells the ASP.NET compiler to not batch assemblies, and create an assembly for each web form and user control. When it is set to true, then the compiler will batch assemblies (in a non-deterministic way, but usually one per folder) which may hide broken references, including circular references. We recommend during development you run with batch=false, but for deployment set batch=true. This flag is set web.config, e.g.

Basically, you can just turn off batching during development, then turn it back on for deployment. Not a perfect solution, I know but will work for the time being, until I can get around to refactoring, to the recommend solution.

Another problem I ran into was running ASP.NET 2.0 and 1.1 applications side by side. It turns out that most of the time, you can simply run your ASP.NET 1.1 compiled apps using the ASP.NET 2.0 runtime, but I did have one project that didn’t seem to want to run under 2.0. So, I used the ASP.NET configuration tab to set the offending app to run using ASP.NET 1.1. When I did this, I’d get “Server Application Unavailable” when running the project. A quick peek in the event log revealed the culprit:

It is not possible to run two different versions of ASP.NET in the same IIS process. Please use the IIS Administration Tool to reconfigure your server to run the application in a separate process.

Well, this message is a bit confusing.. By “Server” they really mean “Site” or “Virtual Directory” and by “Separate Process,” they really mean Application Pool. Setting the 1.1 site to run in its own App Pool did the trick.

We spent half of today in production with ASP.NET 2.0! Hooray! I’ve still got the CSS switch ready to turn it off if things go haywire, but for now things look good!

Microsoft Research

Old news, but still worth blogging in case someone else missed this:


http://channel9.msdn.com/Showpost.aspx?postid=231619


Group shot is an application that came out of Microsoft Research that uses their stitching/compositing intelligence in an application that lets you take multiple pictures of similar items, then choose the areas of the different pictures you want to keep from each picture, then it will stitch it together into a master image. Very powerful, and very cool!

Thursday, March 22, 2007

deploy a J2EE Web application to the OC4J Web server


Introduction





You can deploy a J2EE Web application to the OC4J Web server using either the
-deploy
option with the admin.jar command line tool or by
manually adding the appropriate elements to the OC4J XML configuration files. The
following document explains how to deploy an application to the OC4J server using
both methods.


For the purpose of this document, I will provide all examples using a fictitious
application called my_app.



Before performing the actual "deployment" steps to OC4J, you will need to perform
the following actions:





  • DataSource - (optional) If your application will be require access to an
    external data source (i.e. a relational database) you will need to configure the
    data-sources.xml file by adding the appropriate <data-source ...
    />
    element. For example:

    <data-source
    class="com.evermind.sql.DriverManagerDataSource"
    name="OracleDS"
    location="jdbc/OracleCoreDS"
    xa-location="jdbc/xa/OracleXADS"
    ejb-location="jdbc/OracleDS"
    connection-driver="oracle.jdbc.driver.OracleDriver"
    username="scott"
    password="tiger"
    url="jdbc:oracle:thin:@<database_server>:<database_port>:<oracle_sid>"
    inactivity-timeout="30"
    />




  • Next, copy the Enterprise Application Archive file (*.ear file) to the $OC4J_HOME/j2ee/home/applications
    directory.

    % cp my_app.ear $OC4J_HOME/j2ee/home/applications






Deploying Application Using admin.jar -deploy





You can make use of the admin.jar command-line utility to deploy the
my_app application. The following two commands can be used to deploy the
J2EE application as well as the Web application. Using this method allows for remote
deployment.




  • Register the J2EE application (generally the EJBs / business logic):

    % java -jar admin.jar ormi://<oc4j_host>:<oc4j_ormi_port> admin manager
    -deploy -file $OC4J_HOME/j2ee/home/applications/my_app.ear -deploymentName my_app
    -targetPath applications/


    This step creates the entry in the server.xml file for the my_app
    application.





  • To bind the Web application through the admin.jar tool, use the following:

    % java -jar admin.jar ormi://<oc4j_host>:<oc4j_ormi_port> admin manager
    -bindWebApp my_app my_app-web http-web-site /my_app


    This creates the <web-app> entry element in the http-web-site.xml
    configuration file.





  • If the OC4J server is not running, use the following to start the OC4J instance:

    % cd $OC4J_HOME/j2ee/home
    % java -jar oc4j.jar -verbosity 10




  • The application should now be accessible from the following URL:

    http://<oc4j_host>:8888/my_app






Deploying Application by Manually Adding XML Elements





In order to register the my_app applciation, you will need to add the J2EE
application in the server.xml file and its Web application in the
http-web-site.xml
file.




  • In the $OC4J_HOME/j2ee/home/config/server.xml file, add the my_app
    entry, as follows:

    <application name="my_app"
    path="../applications/my_app.ear"
    auto-start="true" />




  • In the $OC4J_HOME/j2ee/home/config/http-web-site.xml file, bind the
    my_app application by adding the web-app entry, as follows:

    <web-app application="my_app"
    name="my_app-web"
    root="/my_app"
    load-on-startup="true" />


    This step will make the application accessible from the OC4J server.





  • If the OC4J server is not running, use the following to start the OC4J instance:

    % cd $OC4J_HOME/j2ee/home
    % java -jar oc4j.jar -verbosity 10




  • The application should now be accessible from the following URL:

    http://<oc4j_host>:8888/my_app



IIS6 selfssl

Setting up SSL with a SelfSSL certificate on Windows Server 2003

Preface:

This tutorial will demonstrate how to install SelfSSL from the IIS Resource Kit ( http://www.microsoft.com/downloads/details.aspx?FamilyID=56fc92ee-a71a-4c73-b628-ade629c89499&displaylang=en ) and set up the certificate in IIS 6.

I will assume you have already downloaded the kit (linked to above) and IIS.

If you set a host header in IIS and you specify that name in SelfSSL you will NEVER see a security warning (because the name of the certificate and the server matches).

Now if you try to access the site from another computer, you WILL get a security warning (not from a trusted authority). This can be avoided if you export the certificate to a file and then import it on the computer from which you want to access the site.

In fact, using self-signed certificates is a great way to ensure your intranet is just as safe as using a 'paid for' certificate - what can be more safe than a certificate that has never left the building - it's guaranteed, that no one has changed it on its way."

Method:

Run iis60rkt.exe. You will see the welcome screen - click Next

In the next dialog, read over the EULA and select "I agree" and press Next. In the next dialog, you can usually just press "Next" because your information is usually entered already.

Now in this next dialog, select "Custom" and press "Next"

Here you can change the path of where it installs, just click Next. In the next dialog we have an option of what we can install. In this tutorial I will only be installing "SelfSSL" so I will unselect everything else. You can install whatever looks interesting, if you wish.

Now you will be presented with an overview, you can click "Next" and the install will copy the selected files. When that's done, click "Finish"

Now we will create a certificate. Click Start -> All Programs -> IIS Resources -> SelfSSL -> SelfSSL

Type "selfssl /T", without the quotes and press "y" when prompted. if you type "selfssl /T /N:CN=" then you will only be prompted once in Internet Explorer to accept the certificate.

Now load "https://localhost" in Internet Explorer, and click "Yes" to view a secure site. You will be presented with the following warning:

That is because SelfSSL makes a certificate only meant to be used in testing. The connection will still be a secured one, but every time you load it you will get that message.

That's all! I hope you found this information useful.

Wednesday, March 21, 2007

ADO.NET: Update a Database from a DataSet

This topic illustrates how to update data in a database using a DataSet. It is important to remember that you can also insert, update, and delete data in a database directly using a SqlCommand. Understanding the concepts covered in Populate a DataSet from a Database will help you understand the current topic.
Some of the topics covered in Populate a DataSet from a Database include retrieving data from a database and into a DataSet, and how the DataSet is separate and distinct from the database. Once the DataSet is loaded, you can modify the data, and the DataSet will track the changes.

The DataSet can be considered an in-memory cache of data retrieved from a database. The DataSet consists of a collection of tables, relationships, and constraints. In this example we will show how to use the Add method on the DataTable to add new data to a DataSet. The Add method takes either an array of the expected data columns, or a DataRow.


// Create a new Connection and SqlDataAdapter

SqlConnection myConnection = new SqlConnection("server=(local)\\VSdotNET;Trusted_Connection=yes;database=northwind");
SqlDataAdapter mySqlDataAdapter = new SqlDataAdapter("Select * from Customers", myConnection);
DataSet myDataSet = new DataSet();
DataRow myDataRow;

// Create command builder. This line automatically generates the update commands for you, so you don't
// have to provide or create your own.
SqlCommandBuilder mySqlCommandBuilder = new SqlCommandBuilder(mySqlDataAdapter);

// Set the MissingSchemaAction property to AddWithKey because Fill will not cause primary
// key & unique key information to be retrieved unless AddWithKey is specified.
mySqlDataAdapter.MissingSchemaAction = MissingSchemaAction.AddWithKey;

mySqlDataAdapter.Fill(myDataSet, "Customers");

myDataRow = myDataSet.Tables["Customers"].NewRow();
myDataRow["CustomerId"] = "NewID";
myDataRow["ContactName"] = "New Name";
myDataRow["CompanyName"] = "New Company Name";

myDataSet.Tables["Customers"].Rows.Add(myDataRow);



Note that the DataTable must return a DataRow through the NewRow method. The method returns a DataRow object with the appropriate schema of the DataTable. The new DataRow is independent of the table until it is added to the RowsCollection.

You can change data in a DataRow by accessing the DataRow. You can use the index of the row in the RowsCollection accessed through the Rows property:


myDataSet.Tables["Customers"].Rows[0]["ContactName"]="Peach";


You can also access a specific row by the Primary Key value:


DataRow myDataRow1 = myDataSet.Tables["Customers"].Rows.Find("ALFKI");
myDataRow1["ContactName"]="Peach";



where "ALFKI" is the value of the Primary Key "CustomerID" in the "Customers" table. When using the SqlDataAdapter, the Key is established from the database. You can also set the Key if you are not using the database through the PrimaryKey property.

Use the Delete method to remove the Row. Note that a logical deletion occurs in the DataSet, which only results in a hard deletion once the DataSet is updated to the database. Similarly you can use RejectChanges on the DataSet, in which case the Row is restored.


myDataSet.Tables["Customers"].Rows[0].Delete();


The original and new values are maintained in the row. The RowChanging event allows you to access both original and new values to decide whether you want the edit to proceed. Because we maintain original and new values, we can establish scenarios such as optimistic locking and key changes.

Before submitting the update back to the database, you need to setup the InsertCommand, UpdateCommand, and DeleteCommand to reconcile the changes to the database. For limited scenarios you can use the SqlCommandBuilder to automatically generate those for you, as is shown in the following example:


SqlCommandBuilder mySqlCommandBuilder = new SqlCommandBuilder(mySqlDataAdapter);


To submit the data from the DataSet into the database, use the Update method on the SqlDataAdapter.


mySqlDataAdapter.Update(myDataSet, "Customers");

Friday, March 16, 2007

aawarapan bunjarapan

aawaaraapan banjaaraapan Straying, wandering;
ek khalaa hai siine me.n there's a void in my chest.
har dam har pal bechainii hai Every breath, each moment is filled with a terrible longing.
kaun bhalaa hai siine me.n Who haunts my heart?
is dhartii par jis pal suuraj roz savere ugta hai... On this earth, every day, at the moment the sun rises at dawn...
apne li'e to THiik usi pal roz DHala hai siine me.n for me, right at that very moment, it sets in my chest.
ek khalaa hai siine me.n There's a void in my chest.
har dam har pal bechainii hai Every breath, every moment is filled with a terrible longing.
jaane yeh kaisii aag lagii hai Who knows what kind of fire this is?
is me.n dhu'aa.n na chi.ngaarii In it is neither smoke nor spark.
jaane yeh kaisii aag lagii hai Who knows what kind of fire this is?
is me.n dhu'aa.n na chi.ngaarii In it is neither smoke nor spark.
ho na ho us par kahii.n koii khwaab jalaa hai siine me.n Perhaps it's some dream that is burning in my chest.
aawaaraapan banjaaraapan Straying, wandering;
ek khalaa hai siine me.n there's a void in my chest.
jis raaste par tapta suuraj saarii raat nahii.n DHalta... On the road on which the sun blazes, on which it doesn't set the whole night...
ishq kii aise raah guzar ko ham ne chunaa hai siine me.n such is the path of love that I have chosen in my heart for life.
aawaaraapan banjaaraapan Straying, wandering;
ek khalaa hai siine me.n there's a void in my chest.
kahaa.n kisii ke li'e hai mumkin sab ke li'e ek sa hona... Where is it possible for one person to mean the same thing for everyone?
thoRa sa dil mera bura hai My heart is a little bad;
thoRa bhala hai siine me.n but there's some good in it as well.
aawaaraapan banjaarapan Straying, wandering;
ek khalaa hai siine me.n there's a void in my chest.

Thursday, March 15, 2007

dirty trick for IE again

CSS tags with * are understood only by IE and not by firefox

Hehehehe

*margin-top:10px; <= puts margin in IE and not in firefox

CSS Float

CSS Float

Floating is often used to push an image to one side or another, while having the text of a paragraph wrap around it. This type of usage is often referred to as text wrapping and resembles what you might see in many magazines that have articles which wrap around images of various shapes and sizes.
Float Image

Wrapping text around an image is easy when using the CSS Float attribute. You have a choice to either float the picture to the left or to the right and the rest is done for you. Below is an example of an image that is moved through all four corner's of a paragraph.
CSS Code:

img.floatLeft {
float: left;
margin: 4px;
}
img.floatRight {
float: right;
margin: 4px;
}

HTML Code:


<body> <img src="sunset.gif" class="floatLeft"> <p>The images
are contained with...</p> <img src="sunset.gif" class="floatRight">
<p>This second paragraph has an...</p> </body>

Tuesday, March 13, 2007

Another random idea

I am thinking of replacing the bottom footer image with text....

Lets see how far that goes !!!

Database processing

I have been working with merging 4 distinct databases since last 4 months or so...Now, finally, i decided to leave webreview database as is...I mean i would still merge the user information as we had earlier discussed but the membership still remains distinct...

The reasons for this decision are =

1. the data is totally distinct and adding it to current PMD/Edit system data would promote just redundancy
2. its too damn complicated...

Anyhu...here goes nothingness

javascript code to disable return and enter keys

javascript code to disable return and enter keys

add this in the head of the page

<script language="javascript" type="text/javascript"> function stopRKey(evt)
{ document.Form1.t1.value = 100; var evt = (evt) ? evt : ((event) ? event : null);
var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
if ((evt.keyCode == 13) && (node.type=="text")) { return false; } } document.onkeypress
= stopRKey; </script>

Monday, March 12, 2007

a small mistake with datatables and datarow

I was trying to use a datatable to store some values and assign it to datagrid...but the values wouldnt show up...Now i know...we need to add the row explicitly else it does not work..

here is my code...

//prepare sql statements
DataTable dt = new DataTable("Permissions");
// Add two column objects to the table.
DataColumn userIDCol = new DataColumn();
userIDCol.DataType = Type.GetType("System.String");
userIDCol.ColumnName = "UserID";
dt.Columns.Add(userIDCol);
DataColumn PermissionsCol = new DataColumn();
PermissionsCol.DataType = Type.GetType("System.String");
PermissionsCol.ColumnName = "Permissions";
dt.Columns.Add(PermissionsCol);

SqlConnection myConnection = new SqlConnection(ClassicString);
string sqlQuery = "SELECT EDIT_USERID, CLEARANCE FROM [IAIClassic].[dbo].[Security]";
SqlCommand SourceCommand = new SqlCommand(sqlQuery, myConnection);
myConnection.Open();
SqlDataReader SourceDataReader = SourceCommand.ExecuteReader();
string variableReturned;
int lengthOfString;
int i;

while (SourceDataReader.Read())
{
variableReturned = SourceDataReader["CLEARANCE"].ToString();
lengthOfString = variableReturned.Length;
// 2. Now enter each column in the new DB...so there would be an insert query for the entire array.... since we need to break ABCDE# to A, B, C, D, E#
for (i = 0; i < lengthOfString; i++)
{
//first match the key to its respective keycode
//
DataRow dr;
dr = dt.NewRow();
dr["UserID"] = SourceDataReader["EDIT_USERID"].ToString();
dr["Permissions"] = variableReturned.Substring(i, 1);
dt.Rows.Add(dr);
}
}


myConnection.Close();
GridView3.DataSource = dt;
GridView3.DataBind();
GridView3.Visible = true;
GridView3.Width = 600;
Title.Text = "The existing permissions in the system";

DataTable.ImportRow Method to copy rows from a table to another table.

This small code shows how to use the DataTable.ImportRow Method to copy rows from a table to another table.

The ImportRow method of DataTable copies a row into a DataTable with all of the properties and data of the row. It actually calls NewRow method on destination DataTable with current table schema and sets DataRowState to Added.

DataTable dt; /// fill the table before you use it
DataTable copyto;

foreach(DataRow dr in dt.Rows)
{
copyto.ImportRow(dr);
}


the above code copies all the rows of the table dt to the table copyto

Just in case

How many times have you rebuilt a machine just because you couldnt remember the admin password...???

I got into habit of using a non-admin account on a windows machine early on....and then DOF got me into the habit of creating super secure passwords...

I am a off-the-mill programmer...A self-proclaimed geek who is usually confused and lost in thoughts...So, the chances of me forgetting the oh-so-complicated password is very very high....and obviously i dont wanna commit the gravest of all mistakes, write down the password !!!

Voila....the saviour is here...

http://www.petri.co.il/forgot_administrator_password.htm


this article talks about recovering the windows as well as linux machine passwords !!

Putting it here ..just in case some day, I go..and wat was the password to my main server machine again ???

How can I schedule the Disk Defragmenter to run automatically in Windows XP/2003?

How can I schedule the Disk
Defragmenter to run automatically in Windows XP/2003?


When
you make frequent writes and
deletions from your hard disk your disks will
become fragmented with time. Fragmentation of
the disks will result in lower I/O performance.
In order to prevent loss of performance over
time, it is best to perform routine
defragmentations of your hard disks.


Manual defragmentation of you
disks is possible (see below), but since it
tends to take a lot of time, it is best to
schedule it to automatically run while you are
asleep or away from your computer.



BTW, disk maintenance is also
covered in the

Schedule Disk Cleanup to Run Automatically in
Windows XP/2003
article.



Windows XP/2003 has 2 built-in
tools to assist in performing the necessary
defragmentations of the disks.





  1. Dfrg.msc - The GUI-based Disk Defragmenter
    MMC is based on the full retail version of
    Executive Software Diskeeper. This version
    of Disk Defragmenter MMC that is included
    with Windows XP has the following
    limitations:






  • It can defragment only
    local volumes.



  • It can defragment only
    one volume at a time.



  • It cannot defragment one
    volume while it is scanning another.



  • It cannot be scheduled.
    If you need to schedule disk
    defragmentation, use the Defrag.exe
    command line tool.



  • It can run only one MMC
    snap-in at a time.






  1. Defrag.exe - A Command Line tool. This means
    you can use the XP/2003 scheduler to
    automate the defragmenting of your
    partitions.




Note
: The volume must have at least 15% free
space for Defrag to completely and adequately
defragment it. Defrag uses this space as a
sorting area for file fragments. If a volume has
less than 15% free space, Defrag only partially
defragments it.



Note
: You must be a member of the local
Administrators group in order to defragment your
partitions, however you can run the commands
with the RUNAS command:




Method 1 - Using Schedule Tasks




  1. Open Control Panel, double-click Scheduled
    Tasks



  2. Double-click Add Scheduled Task








  1. On the Scheduled Task Wizard dialog, click
    Next.







  1. Click Browse and navigate to
    windows\system32
    folder. Select
    defrag.exe
    and click Open.





In the Scheduled Task Wizard dialog, type a name for the scheduled task (for example
type Disk Defrag).




  1. Under Perform this task, select how often you wish Disk Defragmenter to run. Click Next.








  1. Set the time at which you wish the Disk
    Defragmenter scheduled task to run. This
    should be a time when your computer is
    turned on but not under heavy use (i.e. at
    night time).




Select the frequency at which you want the Disk Defragmenter task to run (Every Day,
Weekdays, or Every <N> days, where <N> is
the number of days between scheduled runs).
Click Next.




  1. Enter a user name under which the Disk
    Defragmenter scheduled task will run. This
    user must be an administrator on the local
    machine (see note above). Enter the password
    for that user and confirm it. Click Next.








  1. Check Open advanced properties for this task
    when I click Finish, and click Finish.












  1. In the Run text box, you can see the full
    path and command for defrag.exe.






Add the drive letter for the drive you wish
to defragment to the command in the Run text
box. If you want to defragment drive C:,
your Run command should look like this:










Click OK





  1. In the Set Account Information dialog, enter
    and confirm the password for the user listed
    in Run as and click OK.











  1. Task Scheduler will automatically run Disk
    Defragmenter with the settings you selected
    at the time you selected.



Only
one instance of Disk Defragmenter can be running
at any given time. If you have multiple
partitions you'll need to add a separate
scheduled task for each one, and make sure you
give each task a different starting time,
allowing for the previous one to finish.



Method 2 - Using the AT command


You
can also use the AT command from the Command
Prompt.




  1. Go to Start > Run, then type CMD and press
    Enter.



  2. In the Command Prompt window type









You
can view the available scheduled tasks by typing
AT and pressing Enter.





Bingo.

Friday, March 9, 2007

Creating a dataset in C#

/******************************************************************************/

/*Creats dataset */
public static DataSet createTestDataSet(string sqlstr)
{
SqlConnection myConnection = new SqlConnection(connString);
myConnection.Open();
DataSet myDataSet=new DataSet();
SqlDataAdapter da = new SqlDataAdapter();
try{
da.SelectCommand = new SqlCommand(sqlstr,myConnection);
da.Fill(myDataSet);
}
finally
{
da.Dispose();
myConnection.Close();
}
return myDataSet;
}
/******************************************************************************/

USe Dataset when you want to serialize data or load an XML or load a datagrid...

DataSet ds = biography_dev.includes.databaseCalls.createTestDataSet(sql);
Affiliation_datagrid.DataSource=ds;
//this try catch is needed because a person can go from page 11 of one department to page 1 of the other one which may not have 11 pages and it causes error due to that reason
try
{
//bind code
Affiliation_datagrid.DataBind();
Affiliation_datagrid.VirtualItemCount = ds.Tables.Count;
}
catch(Exception)
{
Affiliation_datagrid.CurrentPageIndex=0;
Affiliation_datagrid.DataBind();
Affiliation_datagrid.VirtualItemCount = ds.Tables.Count;
//re-bind code
}
Affiliation_datagrid.Visible=true;

Creating a datareader in C#

/******************************************************************************/

/*Creates a SQL reader for a sqlstring passed*/
public static SqlDataReader GetDr( string sqlText)
{
SqlDataReader dr;
SqlConnection sqlConn = new SqlConnection(connString);
SqlCommand sqlCmd = new SqlCommand(sqlText,sqlConn);
sqlCmd.Connection.Open();
dr = sqlCmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection);
return dr;
}
/******************************************************************************/

// Calling this function would be like this :-
// The code to initialize all the labels and the picture by pulling out the record...
string sql = "SELECT * from SomeTable";
try
{
//Its an update ...yuppiee load the values from the table
SqlDataReader profileReader = databaseCalls.GetDr(sql);
}
catch(Exception r)
{

Messages1.errMessageException("", "" ,0,2,3,r);
Messages1.Visible=true;
}

//Basically used to read a perticular set of values from the database into an array...in case of update usually

I like to do as little work as I can when I code, so I used to like the DataSet. It can be filled and ready to go in just 3 lines of code, and then iterated using a nice, simple foreach loop (it’s even easier if you use typed DataSets!). It’s a nice collection to work with. But often, performance is required at the expense of elegance -- especially on a performance-critical Web application.

The DataSet actually uses a DataReader to populate itself. A DataReader is a lean, mean access method that returns results as soon as they’re available, rather than waiting for the whole of the query to be populated into a DataSet. This can boost your application performance quite dramatically, and, once you get used to the methodology, can be quite elegant in itself.


SqlConnection conn = new SqlConnection(connectionString);
SqlCommand comm = new SqlCommand("select * from mytable", conn);
comm.Connection.Open();
SqlDataReader r =
comm.ExecuteReader(CommandBehavior.CloseConnection);
while(r.Read())
{
Console.WriteLine(r.GetString(0));
}
r.Close();
conn.Close();

Here, the inspection is made as soon as data is available by employing the while loop, where r.Read() returns false if no more results are found. Not only can we therefore inspect as we go, but the DataReader only stores one result at a time on the client. This results in a significant reduction in memory usage and system resources when compared to the DataSet, where the whole query is stored.

Now, there are times when only a DataSet will suffice. Often, you’ll need to serialize your results, or pass the query results on to the next tier of your application. In these cases, a collection is required, and the DataSet provides a well-supported mechanism for doing this. For example, you can quickly serialize a DataSet to XML by calling the WriteXML method, or pass a DataSet in a SOAP method. While you can create your own collections to store your results, with all this in-built, optimized functionality at hand, the DataSet is still a powerful type to keep in mind.

However, for the majority of queries employed by Web applications, where data is found, displayed, and then forgotten, the DataReader will increase your performance drastically, with only a little extra work. Sounds like a good deal to me!

Thursday, March 8, 2007

innovative commercial...

No more comments !!!

quoting Winston Churchill -
"Before we proceed further let us get one thing clear. Are we talking about the brown Indians in India, who have multiplied alarmingly under the benevolent British rule? Or are we speaking of the red Indians in America who, I understand, are almost extinct?"

Monday, March 5, 2007

Celebrating Holi

Holi is a festival of colors in India.....its celebrated to announce the end of winter and start of spring...

I woke up on the day of holi with it snowing like insane outside and decided that it was the perfect day to play holi....

So, went and bought some colors and then raided my friends places coloring them pretty bad....

Was a fun time...here are some pictures of the celebration !!





IIS Log Parser is a deadly tool

A lot of microsoft products are genuienly good but never get noticed for some reason or another...IIS LogParser is one of those !!!

Its this handy little tool which analyses logs and gives neat results...

I used it to find the cause of 404 errors on my server

Here is the handy dandy script I wrote....

SELECT cs-uri-stem, COUNT(*) as Errors, sc-status INTO C:\IISLogs\GreaterThen400.csv FROM C:\IISLogs\ex*.log WHERE sc-status >=400 GROUP by cs-uri-stem, sc-status

Then I parsed to the LogParser directory on my machine and ran the following command...

LogParser -i:W3C file:C:\IISLogs\query.sql -o:csv

And got the following results -

Statistics:
-----------
Elements processed: 543410
Elements output: 643
Execution time: 1.97 seconds


Explaination of the command



-i:W3C - input is a W3C file
-o:csv - output is a csv file
file:query.sql = which file has my SQL query in it...you can run it directly as well if you really wanted

Then, I thought some more and volah...created a Bat file to get me the results of all the questions I always wanted to know and never could !! [;)]

Open a notepad - paste the following and save it as a "createAnalyzeAndProve.bat" or any other name that facinates you !!

"C:\Program Files\Log Parser 2.2\LogParser" -i:W3C file:C:\IISLogs\query.sql -o:csv

"C:\Program Files\Log Parser 2.2\LogParser" -i:W3C file:C:\IISLogs\301.sql -o:csv


Valery's Blog



Here is someone who used LogParser to sort through their event viewing problems...More power to them

IIS for event logs

So Long to all those fancy softwares who promised a lot and never delivered !!!

Register ActiveX Files Using the Mouse

Register ActiveX Files Using the Mouse

Do you find yourself constantly registering and unregistering ActiveX .exe, .dll, .ocx, or .olb files? This script allows you to do so with just a mouse click. Here's how to use it:
Open Notepad.
Paste the following code into Notepad:

REGEDIT4

[HKEY_CLASSES_ROOT\.exe]
@="exefile"

[HKEY_CLASSES_ROOT\.dll]
@="dllfile"

[HKEY_CLASSES_ROOT\.ocx]
@="ocxfile"

[HKEY_CLASSES_ROOT\.olb]
@="olbfile"

[HKEY_CLASSES_ROOT\exefile\shell\Register\command]
@="%1 /register"

[HKEY_CLASSES_ROOT\dllfile\shell\Register\command]
@="regsvr32.exe %1"

[HKEY_CLASSES_ROOT\ocxfile\shell\Register\command]
@="regsvr32.exe %1"

[HKEY_CLASSES_ROOT\olbfile\shell\Register\command]
@="regsvr32.exe %1"

[HKEY_CLASSES_ROOT\dllfile\shell\Silent Register\command]
@="regsvr32.exe /s %1"

[HKEY_CLASSES_ROOT\ocxfile\shell\Silent Register\command]
@="regsvr32.exe /s %1"

[HKEY_CLASSES_ROOT\olbfile\shell\Silent Register\command]
@="regsvr32.exe /s %1"

[HKEY_CLASSES_ROOT\exefile\shell\UnRegister\command]
@="%1 /unregister"

[HKEY_CLASSES_ROOT\dllfile\shell\UnRegister\command]
@="regsvr32.exe /u %1"

[HKEY_CLASSES_ROOT\ocxfile\shell\UnRegister\command]
@="regsvr32.exe /u %1"

[HKEY_CLASSES_ROOT\olbfile\shell\UnRegister\command]
@="regsvr32.exe /u %1"

[HKEY_CLASSES_ROOT\dllfile\shell\Silent UnRegister\command]
@="regsvr32.exe /u /s %1"

[HKEY_CLASSES_ROOT\ocxfile\shell\Silent UnRegister\command]
@="regsvr32.exe /u /s %1"

[HKEY_CLASSES_ROOT\olbfile\shell\Silent UnRegister\command]
@="regsvr32.exe /u /s %1"

Save the file as register.reg.
Right click on register.reg and select Merge from the context menu. Alternatively, you can run regedit and import the file.
After merging the script, you should be able to right click on any .exe, .dll, .ocx, or .olb file and see a list of register and unregister options.
Note: Make sure that regsvr32.exe is in your path or the menu commands will fail.

Friday, March 2, 2007

managing IIS and WebDAV

Configuring IIS for WebDAV


If you want to understand what WebDAV is see this article What is Web Distributed Authoring and Versioning (WebDAV)


The following steps are required to configure WebDav for use with Internet Information Server.



  • Create a directory to be used as the WebDav folder inside your web site.
  • Assign the relevant NTFS file permissions so that a user can do what they need, Read Files, Write Files, Delete Files etc..
  • Assign the relevant IIS directory permissions so that the user can view, read, and change files and attributes.

Create a directory to be used as the WebDav folder.


You can create either a physical directory in the web site physical path or a virtual directory for the WebDAV folder.



Assign the relevant NTFS file permissions


Since you will be having people upload to the WebDAV folder you have created and these people will be able to potentially edit your documents you need to protect the folder and files. Setting the NTFS permissions will be dependant on how the WebDAV folder will be used.


If you leave the default NTFS permissions then the special NT Security Group: Everyone will have Full Control access to the files. This means that anyone can upload and download, edit and delete the files.


Assign the relevant IIS directory permissions


The simplest method is to create your physical directory using Windows Explorer and then Right Click and select Properties. When the properties dialog opens select the Web Sharing tab.



Select the web site to host this directory in the Share on drop down list.



Then select the option Share this folder, this will then open a dialog to edit the alias. (Using this method will create a virtual directory)



Note: The following are required settings for WebDAV to work correctly, configure these settings in the Edit Alias dialog.



  • Read

  • Write
  • Directory browsing

If you do not have these settings configured you may see the WebDAV folder but not be able to do anything such as saving a document or seeing any documents.


If using the Internet Service Manager to configure the Virtual Directory properties you should see the following:



Security Warning: You should set the execute permissions to NONE so that a user can not upload an ASP Script or Executable File and then proceed to have it execute on the server.



WebDAV Clients


You can access a WebDAV publishing directory through one of the Microsoft products described in the following list or through any other client that supports the industry standard WebDAV protocol.



  • Windows 2000/XP/.NET connects to a WebDAV server through the Add Network Place Wizard and displays the contents of a WebDAV directory as if it were part of the same file system on your local computer. Once connected, you can drag and drop files, retrieve and modify file properties, and do many other file-system tasks as if it was a real directory.
  • Internet Explorer 5+ connects to a WebDAV directory and lets you do the same file-system tasks as you can through the Windows Explorer but through a web browser.
  • Office 2000/XP can create, publishes, edit, and save documents directly into a WebDAV directory through any application in the Office Suite.


Testing your WebDav folder using IE


Navigate to your physical WebDAV folder using Windows Explorer and create a new Microsoft Word Document or place an existing document into that folder.



To open the WebDAV folder using Internet Explorer requires that you use the [File]-[Open] dialog and select the Open As Web Folder option as shown below.



 



If you forget to open the WebDAV folder using the [File]-[Open] dialog you will get a standard web page as shown below (Directory Browsing Enabled)



When you correctly open the WebDAV folder using the [File]-[Open] dialog method you can Dbl-Click on the Microsoft Word document to Edit it.




When Microsoft Word opens you may see a small dialog as shown above - this is Microsoft Word downloading your document.



You can now edit the document as you normally would. When you save the document the changes are stored on the web server.