Tuesday, December 23, 2008

MSN Live Error code: 80048820 Extended error code: 80048439 Fix

Option 1
Type the followining in the Run dialogue box:
regsvr32 softpub.dll Wintrust.dll Initpki.dll Rsaenh.dll Mssip32.dll Cryptdlg.dll
Again type the followining in the Run dialogue box:
regsvr32 Dssenh.dll Gpkcsp.dll Slbcsp.dll Sccbase.dll

Option 2
Open Internet Explorer -> GOTO Tools -> Internet Options
Select Connetion Tab
Click Lan Settings
Uncheck all except ‘Automatically detect settings’
Click Ok

Option 3

GOTO MSN Tools menu option
Select Connection
Remove all settings
save

Wednesday, October 1, 2008

Trick Questions

You receive some data from UI and need to populate table Customer if the name received from UI does not exist in database. Which of options below should be used for this purpose:

1.

IF NOT EXISTS ( SELECT * FROM Customer
WHERE Name = @CustomerName )
INSERT INTO [Customer]
( [Name])
VALUES
( @CustomerName)

2.

INSERT INTO [Customer]
( [Name])
SELECT @CustomerName
WHERE NOT EXISTS ( SELECT * FROM Customer
WHERE Name = @CustomerName )



Correct answer:
Option 2 is the one to use
Explanation:
Option 1 has 2 separate statements. The first one applies locks relevant table resources in order to perform check for existence. As soon as it's completed SQL Server releases all applied locks. At the moment parallel SPID may insert a record into the table BEFORE following INSERT statement has applied its locks.

Therefore initial check may be irrelevant at the moment when following INSERT starts. IF there is a unique constraint on Customer.Name INSERT would fail despite you've done the check for existence.

The second option does everything in a single transaction. It applies the locks and holds it until INSERT transaction has finished its job. Another SPID cannot insert another row until all locks on the object applied by INSERT statement are released.

So, the first option is unacceptable, it relies on a user's luck not to have another user doing same thing at the same time. Of course, probability of the failure is quite low but it's a possible event. In active transactional systems with hundreds of transactions per second it does not look so improbable.

Script to run the test:

USE pubs
GO
CREATE TABLE Customer (
ID int IDENTITY(1,1) NOT NULL,
Name nvarchar(100) NOT NULL,
UNIQUE (Name)
)
GO
DECLARE @CustomerName nvarchar(100)
SET @CustomerName = 'Customer2'

IF NOT EXISTS ( SELECT * FROM Customer
WHERE Name = @CustomerName )
BEGIN
WAITFOR DELAY '00:00:05'
/* this 5 sec pause lets you insert same row from another QA window:
DECLARE @CustomerName nvarchar(100)
SET @CustomerName = 'Customer2'
INSERT INTO [Customer]
( [Name])
VALUES
( @CustomerName)
*/

INSERT INTO [Customer]
( [Name])
VALUES
( @CustomerName)

END

SET @CustomerName = 'Customer3'
INSERT INTO [Customer]
( [Name])
SELECT @CustomerName
WHERE NOT EXISTS ( SELECT * FROM Customer
WHERE Name = @CustomerName )

GO
select Object_Id('Customer')

DROP TABLE Customer




What will be the output?

Declare @var int
Select @var = isnull(@var,1) + Value1
From (Select 1 Value1 Union All Select 1 Union All Select 2) as a
Select @var

Answer: 5, the sql behave like v=v+1




What will be the count against each category? Each row in the result is shown as a pair in the answers.

CREATE TABLE #CATEGORY
(CATID INT
,VAL1 INT)

INSERT INTO #CATEGORY VALUES(1,NULL)
INSERT INTO #CATEGORY VALUES(2,1)
INSERT INTO #CATEGORY VALUES(3,2)

CREATE TABLE #DATA
(VAL1 INT)

INSERT INTO #DATA VALUES(1)
INSERT INTO #DATA VALUES(1)
INSERT INTO #DATA VALUES(1)
INSERT INTO #DATA VALUES(2)
INSERT INTO #DATA VALUES(2)
INSERT INTO #DATA VALUES(3)

SELECT C.CATID, COUNT(*)
FROM #DATA D
INNER JOIN #CATEGORY C ON C.VAL1 = D.VAL1 OR C.VAL1 IS NULL
GROUP BY C.CATID


Answer: 1 6, 2 3, 3 2




Simulating memory pressure

You have been asked to optimize a stored procedure that runs against a terabyte-sized database. The stored procedure executes several steps consecutively. The performance problems appear to be mainly I/O related.

You install a severely trimmed down test version of the database (1 GB in size) on your desktop computer running SQL Server Developer Edition. Before you start optimizing, you want to establish a baseline by timing the stored procedure on your development machine, so that you can later compare performance after adding indexes and tweaking code.

However, your desktop has 2 GB of memory installed, and you are concerned that the performance test results may be skewed because the test version of the database fits entirely in cache. What is the best way to simulate the production circumstances as closely as possible?



Correct answer:
Execute sp_configure and RECONFIGURE to limit server memory to 512 MB, then restart the SQL Server service.
Explanation:
Executing "EXEC sys.sp_configure N'max server memory (MB)', N'512'" followed by "RECONFIGURE WITH OVERRIDE" will limit the memory used by your server to 512 MB. Since SQL Server might have already allocated more memory, which will not be released immediately, a reboot will force this memory setting to be respected.

Creating a bigger test database will also work, but involves a lot more work, will cause your tests to run longer, and might require you to clean up your collection of holiday pictures. Removing some RAM from your computer works as well, but will cause all other processes in your computer to slow down as well. Not recommended (especially if you are as clumsy in handling electronic equipment as I am)

Executing DBCC FREEPROCCACHE before starting the tests will cause the FIRST query to run with no data in cache, but the remaining steps of the stored procedure will once more be able to read data from cache. This is not a good simulation of the production circumstances. Starting memory hungry applcations might indeed cause available memory for SQL Server to be reduced. But it will also cause extra strain for the CPU, and you might get SQL Server and the other applications "fighting" for memory or Windows starting to page some applications in and out of memory. Again, not a good simulation of the production circumstances.

Wednesday, September 17, 2008

Referesh page automatically after a timespan

add "Refresh" with some values in sec to the page header

c# - Response.AddHeader("Refresh", "30");

Thursday, September 11, 2008

Popup a save dialog box along with refreshing the same page

insert a label on the page which is visible-false

when you need to pop the save dialog box.
insert "" into the label text and make the control visible.

this will result in pop up of dialog box (because of iframe, it is treated as a separate request) and refresh the page too.

Wednesday, September 10, 2008

Force Windows Authentication popup (Firefox)

C sharp:

Response.ClearHeaders();
Response.AppendHeader("Cache-Control", "no-cache; private; no-store; must-revalidate; max-stale=0; post-check=0; pre-check=0; max-age=0"); // HTTP 1.1
Response.AppendHeader("Pragma", "no-cache"); // HTTP 1.1
Response.AppendHeader("Keep-Alive", "timeout=3, max=993"); // HTTP 1.1
Response.AppendHeader("Expires", "Mon, 26 Jul 1997 05:00:00 GMT"); // HTTP 1.1
Response.Close();

Execute the following code on some action and browser will popup a dialog box for authentication

no-cache here refers to asp.net Session. If you remove it from the Cache-Control list, it will retain the Session variables.

Firefox Windows Authentication - removing dialog box

Note to self: Firefox Windows Authentication

To enable windows authentication on your domain.

1. Open Firefox

2. Navigate to the url about:config

3. Locate the following preference names and put as the value the comma separated values of the address roots.

network.automatic-ntlm-auth.trusted-uris

network.negotiate-auth.delegation-uris

network.negotiate-auth.trusted-uris

Your value should look something like this: localhost,server1,server2,serverX


Contents from

Wednesday, August 15, 2007

Classes

JavaScript doesn't have a keyword specific to class, so we must go back to basics and develop classes in a different way. This isn't very difficult.

javascript class object is create as soon as you put a '.' after a var name. eg 'var summary.total' makes a 'summary' object with 'total' property. But the drawback off this technique is that you have to create class object quite often, but helps processing at client.

eg:
lets take an example, summary report which displays 'type' based total values. each type can have various 'currencies' amounts.

solution:
var summary = new Array();
summary.typeList = new Array();
summary.currencyList = new Array();
summary.riembersmentAmount=0;
summary.riembersmentCurrency=getRiembersmentMoney().currency.getSymbol();

summary[TypeId]=new Array();
summary[TypeId].riembersmentAmount=0;
summary[TypeId].riembersmentCurrency=getRiembersmentMoney().currency.getSymbol();
summary[TypeId].currencyList=new Array();

summary[TypeId][CurrencyId]=new Array();
summary[TypeId][CurrencyId].amount=0;
summary[TypeId][CurrencyId].currency= (assign each type currency here);

now point to remmber summary, summary[0] and summary[0][0] are all different i.e
summary -> is the summary object
summary[x] -> is the type object with each type riemberment amount and currency, where x is TypeId
summary[TypeId][y] -> is the currency object for each type object with amount and currency, where y is CurrencyId


Class Properties

script inside html-head

function House(rooms,price,garage) {
this.rooms=rooms;
this.price=price;
this.garage=garage;
}
house1=new House(4,100000,false);
house2=new House(5,200000,true);
with (house1) document.write('House 1 has '+rooms+' rooms, '+(garage?'a':'no')+' garage, and costs £'+price);
with (house2) document.write('House 2 has '+rooms+' rooms, '+(garage?'a':'no')+' garage, and costs £'+price);

script inside html-head

We define a House function that takes three parameters, rooms, price and garage. The function uses the this keyword to create an object.

When we call the House function, we assign the result to our variable, which becomes an object.

So, identical code would be:

house1=new Object();
house1.rooms=4;
house1.price=100000;
house1.garage=false;

We would have to type this in for all houses, which would be very tedious and is why we use the class structure instead.

When we display the details for a house, I have introduced the ternary operator, '?:'. The ternary operator is a compacted version of:

if (garage) str='a'; else str='no';

(garage?'a':'no') means if garage is true, return 'a' else return 'no'. Using the ternary operator removes a line of code, and avoids having to create a new variable.

Similary in JavaScript, we would define the Pet class as follows:

// JavaScript Pet class

function Pet(name) {
this._name = name;
}

Pet.prototype._name;

Pet.prototype.getName = function() {
return this._name;
}

Our JavaScript program (most likely a web page) could create an instance of Pet and invoke the getName() method as follows:

var p = new Pet("Max");
alert(p.getName());


The following list compares the JavaScript version to the C# version:

*

In C#, a constructor is defined using this syntax:

public class Pet() { // ...

In JavaScript, class constructors are defined as functions:

function Pet(name) { ... }

However, as in C#, class instances are created using the new keyword:

var p = new Pet("Max");

*

Methods and properties in JavaScript are attached to a class via the prototype keyword. For example, the class defines a prototype property called _name that will contain the name of the Pet, and a prototype method named getName() that returns the value of _name.

A complete description of prototype-based object modeling is beyond the scope of this article; suffice it to say that this is the recommended syntax for defining the properties and methods that your JavaScript class will expose.
*

Unlike C#, JavaScript properties and methods are untyped: the _name property is not declared as a string, and the getName() function is not declared to return a string. There is no compile-time check for proper type usage. The burden of ensuring proper type usage is placed entirely on the developer.
*

A JavaScript class must always refer to its own properties and methods using the this keyword; unlike Java or C#, JavaScript objects do not provide an implicit this scope.
*

JavaScript does not support any concept of method or property visibility: every property and method is always public. The developer is responsible for ensuring proper usage of a JavaScript class's members. As a result, it is a common convention to tag member variables that should be considered private with a leading underscore, as in the _name property in the example.
*

C# method names typically use the upper camel case naming convention, in which the first letter of each word is capitalized, including the first word; JavaScript (and Java) methods are commonly named using lower camel case, in which the first letter of every word except for the first is capitalized.



Javascript Class Links

http://www.codeproject.com/aspnet/JsOOP1.asp

Contract Class