Sunday, March 29, 2009

.Net 3.5 XAMP: {System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.UIPermission, mscorlib, Version=2.0

Today I am trying to work on WPFBrowserApplication. I face the following error. I don't understand how to resolve this problem. I tried on search engine. Then I go to the project's property. There I found in the 'Security' tab that the permission was given are: FileDialogPermission & IsolatedStorageFilePermission. But for this I need FileIOPermission too. So I check radio button 'This is a full trust application'. Then I tried to run the application. And its running very fine. Your security tab should look like the following:

Sometimes problems are too easy then time spent to resolve it.

Vijay Modi

Thursday, March 26, 2009

MS Sql Server: Alter Table set default value

Hi Friends,

Do you want to know how to Alter Table for adding new column with Default value? The sysntax of sql server is:

ALTER TABLE table
{
ADD
{
column_name data_type [ ( size ) ]
[ DEFAULT value ]
{ [ NULL | NOT NULL ] | [ { PRIMARY KEY | UNIQUE } ] }
{ [ CONSTRAINT constraint_name ] }
}
|
ALTER COLUMN column_name
{
data_type [ ( size ) ] [ ( precision [ , scale ] ) ]
[ NULL | NOT NULL ]
}
|
DROP { COLUMN column_name | [ CONSTRAINT ] constraint_name }
}

table
Specifies which table is to be altered.
column_name
The name of the column being added, altered, or dropped.
data_type
The data type of the column being added or altered.
size
Is the length of the data that can be entered into a field.
DEFAULT value
Is the default value for the column being altered.
NULL | NOT NULL
Is a parameter that indicates whether a column can or cannot contain null values.
PRIMARY KEY
Is a parameter that identifies the column or set of columns whose values uniquely identify each row in a table. Each table can only have one primary key constraint.
UNIQUE
Is a constraint that enforces the uniqueness of the values in a set of columns.
constraint_name
The name of the constraint to be added or dropped.
precision
Specifies the precision for the data type.
scale
Specifies the scale for the data type.
The ALTER TABLE statement can be used to modify an existing table by adding, altering, or dropping columns and indexes.

Reference: http://www.devguru.com/technologies/t-sql/7120.asp

So when you want to set the default value when you are adding a new column in the databse table, you can use the following example. I have created a column named 'tempTest' and its datatype is 'bit' and default value is '0' i.e. false.

ALTER TABLE tblTable
ADD isTempTest bit NOT NULL
CONSTRAINT [DF_tblTable_isTempTest] DEFAULT ((0))

I have added CONSTRAINT 'DF_tblTable_isTempTest' to set the default value 0.

You can add you comment here.

Saturday, March 21, 2009

ASP.Net Error: The web server is not configured correctly

This error will be as follows:



I resolve this error by following steps:

1> Right click on the project and select property option.

2> Go to the Web tag and you have to set the Use Visual Studio Development server instead of User IIS Web Server.



I have resolved this problem just by following above steps. I think it will help you to resolve your problem too.

Sunday, March 15, 2009

DataReader problem + OutPutParameter

I was faced this problem yesterday. I search on Google Search engine, but found that we cannot get the OutPutParameter before closing the datareader. So if you want to get the output parameter, you have to close the datareader. After closing datareader, you can got the output parameter. But after closing the datareader you cannot retrieve out data. So if you want to resolve this problme, You have to go through the following :

If you output parament name is @IsExist
SET it with your conditions and query in Stored Procedure
SET @IsExist =1

Then Just add the SELECT statement like :
SELECT @IsExist AS IsExist

Now you can get this variable from Coding(C#) as following
IDataReader = db.Execure(dbCommand);
bool blnIsExist = (Boolean)dr["IsExist"];

Enjoying na:)
Regards,
Vijay Modi

Thursday, March 12, 2009

Server Side ViewState + Performance Improvement

I assume you all who are reading this article knows about ViewState. So now some times our webpage contains lot of controls, or datagrid/gridview or some dead controls. In this situation it can grow very large. And if we are using viewstate then It will dead effect on performance.

So the solution is to remove viewstate from the client side and keep it on Seaver. There are some drawbacks to store the it on Searver Side. What I am doing is that I have override the method that store and retrieves the ViewState, namely SavePageStateToPersistenceMedium and LoadPageStateFromPersistenceMedium. By overriding these two intrinsic methods, we can intercept the ViewState process and perform our magic. What we are doing is simply this: You have a bunch of baggage. Probably way too much. But you only really need it when you visit the server (such as on a postback). So, instead of making you carry it all with you (which can slow down the plane and make other passengers very unhappy), we are going to arrange for you to leave it in a special place at the server, and pick it up again when you get back there. Everything works the same; you just don't have to lug it all with you. Make sense?

This is far from a new idea; there are a number of implementations of this technique. The best one I found is by Robert Boedigheimer here. Robert's solution provides a new BasePage class which handles these operations, and a viewStateServerMgr class that handles the serialization and deserialization. His implementation is the only one I've seen that also accounts for the fact that with IE, users can hit the back button and we would need to "go back" to the previous viewstate for that page in the cache. Robert made the assumption that since ViewState is unique to each user, he would store and retrieve the ViewState for each page in Session state. However, there are at least three other "places" that we can stick our serialized ViewState object, and we can still account for unique users with a unique key such as the SessionID. If we do this, we can set Session to be readonly (assuming we don't need to write to it) and thus get an additional performance boost. Those options are Application, Cache, and a static global class instance holding, for example, a Hashtable.

A simplified code example of this model, with a different implementation of a unique user key, could be as follow:
protected override void SavePageStateToPersistenceMedium(object viewState)
{
string str = "VIEWSTATE_" + Request.UserHostAddress + "_" + DateTime.Now.Ticks.ToString();
Cache.Add(str, viewState, null, DateTime.Now.AddMinutes(Session.Timeout),TimeSpan.Zero, CacheItemPriority.Default, null);
RegisterHiddenField("__VIEWSTATE_KEY", str);
RegisterHiddenField("__VIEWSTATE", "");
}

protected override object LoadPageStateFromPersistenceMedium()
{
string str = Request.Form["__VIEWSTATE_KEY"];
if (!str.StartsWith("VIEWSTATE_")) {
throw new Exception("Invalid viewstate key:" + str);
}
return Cache[str];
}

So what I did was to wire up Robert's class with some choices that could be set in the web.config -- to make it automatically use Session, Application, Cache, or my global static class, depending on the web.config setting. I then set about to create two pages. The first page uses Robert's BasePage class to inherit from, and implements the server - side ViewState scheme. The second page inherits from the typical System.Web.UI.Page class, and Viewstate is stored "in the page" as usual. Each page is essentially the same, and each page creates 1000 small viewstate entries in the Page_Load handler on first load. Each page also has a bit of javascript written to it with "Defer" - which makes the script wait until the page and all other script is rendered, and then it causes the page to postback. In this manner, I could easily run a series of web stress tests with Homer (now called "Web Application Stress") and I wouldn't have to bother with making a GET and a POST in my tests. All I am really interested in is the throughput and average requests per second under load for each scenario.

As an informational note, many developers will ask "Why didn't you use ACT from Visual Studio.NET?". ACT is great for demos where you want to show people a nice real-time graph, but my personal opinion is that it is nowhere near as reliable or feature-rich as Homer. After a number of years of this testing thing, including several eye-opening weeks at the MS Testing Lab in Charlotte, I have come to trust Homer.

Before going any further, let's take a look at the test results, which may
surprise you. We ran this test with a client machine and a server machine over a
wireless network. The server is a P4 with 1 GB RAM running Windows Server 2003
and IIS in Worker Process Isolation (HTTP.SYS) mode. We ran a two minute test
with 20 simultaneous threads and no delay. This can be considered moderate
stress. None of the tests had any HTTP or socket errors. The regular ViewState
test without the server-side scheme is in the first column, then the four server
side schemes follow:
VIEWSTATE WEB STRESS COMPARISON
TEST NAME VIEWSTATE SESSION APPLICATION CACHE GLOBALS
NUMBER OF HITS 3322 18483 18476 20170 16723
REQUESTS /SEC 27.64 153.8 153.74 167.84 140.32
TOTAL BYTES REC'D (KB) 68016.63 22923.25 22977.13 25074.51 20798
PERCENT DIFFERENCE

N/A


456.44% 456.22% 507.24% 407.67%

As can be seen above, the winner is - surprise - storing the ViewState in
Cache, at almost 168 requests per second. That is an approximate 500
percent improvement in throughput
over regular ViewState. All of the
server-side options outperformed regular ViewState, with static global Hashtable
storage being the worst performer. You can download the solution I used to
create these tests below, and tweak it if you like. I'd be interested in anyone
else's results in this area.

Conclusion: ASP.NET ViewState is a great invention that makes the developer's life easier. It also can create a lot of HTML baggage that slows down performance. By storing ViewState in either Session or Cache, you can have your ViewState and eat it, too.
Taking the time to develop a quality stress testing scenario to prove out (or disprove) one's hypotheses provides the scientific basis in fact to help developers make educated, sound decisions about their application architecture.

You can get an example of it from the following link:

Download the Solution that accompanies this article

Reference: Peter A. Bromberg : http://www.eggheadcafe.com/articles/20040613.asp

http://www.codeproject.com/aspnet/ServerViewState.asp
Regards,
Vijay Modi

Sunday, March 8, 2009

The following module was built either with optimizations enabled or without debug information

When you find this bug, follow the following steps in sequence:
1>Go to bin folder of you project and remove the dll where you find above error.
2> Browse the project and right click on bin folder and uncheck readonly checkbox. Click OK.
3> Right click on project and click on add reference option. Add the existing project as dependency project.
4> Build web service and test it.

It will resolve your problem. If you find more help send me reply he in comments.

Regards,
Vijay Modi

Saturday, March 7, 2009

Button onClick and onClientClick

Today I got a comment regarding what is the difference between onClick and onClientClick. So I think to write a small article on it.

Please find the following code for. I write the code for .aspx page. Copy and paste this code in your aspx page.

========================================================================================
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
<script language="javascript" type="text/javascript">
function confirmthis()
{
if(confirm("Do you want to do a server trip?"))
{
return true;
}
else
{
return false;
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" OnClientClick="return confirmthis();" Text="Click Me..." /></div>
</form>
</body>
</html>

========================================================================================

Copy and paste following code in your code behind(aspx.cs) page.

========================================================================================
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button1_Click(object sender, EventArgs e)
{
TextBox1.Text="U click Button1"
}

========================================================================================

Now run your project. just Click on the button "Click Me...". It will ask to "Do you want to do a server trip?". If you select YES then you will do a server trip and when you select NO you will not redirect to server. So here for validation purpose we are using onClientClick and for doing process on server side, we are using onClick.
Best Regards,
Vijay Modi

Friday, March 6, 2009

JavaScript + Blinking /Flash behind TextBox

Hi today I trying to make a blinking text box and found an important script from the web. I have created a html page and test it. Its really very good script. So if do you want to craete a blinking textbox, go through the following code and you can create your own blinking textbox.

<HTML>
<HEAD>
<TITLE> Blinking TextBox </TITLE>
<script>
window.Blink = function(args)
{
args = (/,/.test(args))? args.split(/,/): [args,'#FFD100',10];
var who = document.getElementById(args[0]);
var count = parseInt(args[2]);
if (--count <=0)
{
who.style.backgroundColor = '';
if(who.focus) who.focus();
}
else
{
args[2]=count+'';
who.style.backgroundColor=(count%2==0)? '': args[1];
args='\"'+args.join(',')+'\"';
setTimeout("Blink("+args+")",500);
}
}
</script>
</HEAD>

<BODY onLoad="Blink('name');">
<table>
<tr>
<td width="50"><b>Name:</b></td>
<td width="300">
<input id="name" type="text">
</td>
</tr><tr>
<td width="50"><b>E-mail:</b></td>
<td width="300">
<input id="email" type="text">
</td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="button" value="Submit" onClick="alert('Your form would have been submitted')">
</td>
</tr>
</table>
</BODY>
</HTML>

Regards,
Vijay Modi

Wednesday, March 4, 2009

JavaScript Events

Hi Friends,

I am here giving some Events regarding buttons in JavaScript.


onClick

We've already used this event quite a lot. But you can use it with buttons, images, links, radio buttons, check boxes. Here's a simple onClick event used with an image:


<IMG SRC = red.jpg onClick = "alert('No stealing the images!')">



onDblClick

Same as above, really. Try inserting Dbl into onClick and see what happens.


onKeyDown

This events fires when a key on your keyboard is pressed. It applies to buttons, textboxes, text areas, and links. If you had a search box on a form, for example, you might want to activate the search when the user presses the Return/Enter key on the keyboard. For Netscape users, though, you need to use this:


window.captureEvents(Event.KEYPRESS)



And that's only the start of your problems!


An easier example of the KeyDown event that works in both browsers is this:


<INPUT type = text onKeyDown = "alert('Key pressed')">



onMouseOver

You've seen this in action already when we wrote the script for the "dancing hand". Associated events are onMouseOut and onMouseDown. They are mainly used for links and images. A typical use of onMouseOver is to swap images around when creating a rollover effect.


Onblur

This event takes places when objects lose focus. If you click inside one text box then click outside it the textbox has lost focus. That's when the onBlur event fires.


<INPUT TYPE = text onBlur = "alert('Lost focus')">



Here's an example. Click inside the first text box, then click inside the second one.


When you move away from the textbox, you should see the alert box. You can write code to check if something like an email address is correct. If not, you can reset the text box to a blank string.


onSubmit

This is a very useful event that can be used for data validation on a form. You can use this event with a Submit button. The details on the form can then be checked for errors. If you catch any errors, you can then stop the form's details from being submitted. Here's an example. Note the use of the word return. This is set to a Boolean value. If return is false then the form doesn't get submitted; if it's true then the form is submitted. (More about return in the next section.)


<FORM name = f1 onSubmit = "return Validate()">


<INPUT Type = Submit Value = " Send ">


</FORM>



The form is not much good because it only has a submit button. But notice where the onSubmit event is - in the FORM tag, and not with the Submit button.


Here's the Validate() function. It doesn't do any checking. All it does is to display an alert message.


function Validate() {


Details = false


if (Details == false) {


alert("errors detected")


return false


}


if (Details == true) {


alert("Form Submitted")


return true


}


}



In the function, we've set a variable (Details) to false. This is just for testing purposes, and means the user has filled out the form incorrectly. Look at the two return values, though. If the Details are false then return gets set to false, and the form isn't submitted; if the Details are true then return is true, and the form is submitted.


If you want, add a Method and an Action to your Form. Like this one:


<form name = f1 onSubmit = "return Validate()"


Method = post Action="Mailto:MyEmailAddress@MyISP.com" Enctype="text/plain">



(The Enctype will send the details in plain text that's much easier to read.)


Test out the code on a web page. Change the Details variable to true and click the button. We're going to do some real error checking in the next section, and we'll meet onSubmit again.


Speaking of that next section - let's get right to it.


Reference: http://homepage.ntlworld.com/kayseycarvey/jss3p3.html


Regards,


Vijay Modi