Thursday, September 29, 2011

What is the purpose of "sp_resetstatus" system stored procedure ?

This system stored procedure is used to reset the database status from SUSPECT to normal.

The following are the considerations :
1. You should be under 'sysadmin' server role.
2. Should not be under Transaction. It will throw an err as follows
i.e: The procedure 'sp_resetstatus' cannot be executed within a transaction.
3. Database name should be valid and available
i.e: The database '' does not exist. Supply a valid database name. To see available databases, use sys.databases
4. The database should not be a snapshot. It should be a source database.
i.e: Cannot run sp_resetstatus against a database snapshot.
5. The database should be already in SUSPECT mode.
i.e: The suspect flag on the database "" is already reset.

Input field -get value

problem

It is not possible in asp.net to get value in server side without runat=server tag but the problem solved



Solution

It’s simple: Request.Form returns NameValueCollection. GetValues is a NameValueCollection class method which gives us the requested result.
Request.Form.GetValues(”txtSomeText”) returns a string array with all the values.




Operator ===



Have you ever used the strict equal operator? I learned about it few days ago…
Below is a quick explanation of its behavior:

"The strict equal to operator returns true if both operands are equal (and of the same type). It doesn't perform any data type conversion, so an expression like 1 === true returns false and 1 === "1" also returns false, because this operator checks for the type of the operands. 1 is a numerical value and “1″ is a string value; their types are different."

Hid Div and white spaces it occupy




Pic the div by there ID and hide it through Jquery or javascript .I m here just doing with it by javascript.


Problem


Most of the developers will say “I can use javascript and CSS ‘visibility’ property to do that”, but shortly after that they’ll realize that this is not enough. This solution will hide the div tag content, but the space it occupies will stay.

You can reproduce this behavior using the code below:

if (objDiv.style.visibility == 'visible' ||
objDiv.style.visibility == '')
{
objDiv.style.visibility = 'hidden';
}
else
{
objDiv.style.visibility = 'visible';
}
where objDiv is the div object which you’re trying to hide.

Solution

It’s simple - initialize “display” property in addition. So the above code will look like:

if (objDiv.style.visibility == 'visible' ||
objDiv.style.visibility == '')
{
objDiv.style.visibility = 'hidden';
objDiv.style.display = 'none';
}
else
{
objDiv.style.visibility = 'visible';
objDiv.style.display = 'block';
}
css, div, hide, javascript white space

Wednesday, September 21, 2011

Sql amazing queries

Find no of connection on database



SELECT db_name(dbid) as DatabaseName, count(dbid) as NoOfConnections,
loginame as LoginName
FROM sys.sysprocesses
WHERE dbid < 0
GROUP BY dbid, loginame

You can kill all connection are you using currently by running below query


DECLARE @DatabaseName nvarchar(50)
SET @DatabaseName = N'myDatabaseName'
--SET @DatabaseName = DB_NAME()

DECLARE @SQL varchar(max)
SET @SQL = ''

SELECT @SQL = @SQL + 'Kill ' + Convert(varchar, SPId) + ';'
FROM MASTER..SysProcesses
WHERE DBId = DB_ID(@DatabaseName) AND SPId <> @@SPId

-- SELECT @SQL
EXEC(@SQL)
DEALLOCATE my_cursor

Creating a Calendar in a single SQL statement in oracle

SELECT LPAD( MONTH, 20-(20-LENGTH(MONTH))/2 ) MONTH,"Sun", "Mon", "Tue",
"Wed", "Thu", "Fri", "Sat"
FROM (SELECT TO_CHAR(dt,'fmMonthfm YYYY') MONTH,TO_CHAR(dt+1,'iw') week,
MAX(DECODE(TO_CHAR(dt,'d'),'1',LPAD(TO_CHAR(dt,'fmdd'),2))) "Sun",
MAX(DECODE(TO_CHAR(dt,'d'),'2',LPAD(TO_CHAR(dt,'fmdd'),2))) "Mon",
MAX(DECODE(TO_CHAR(dt,'d'),'3',LPAD(TO_CHAR(dt,'fmdd'),2))) "Tue",
MAX(DECODE(TO_CHAR(dt,'d'),'4',LPAD(TO_CHAR(dt,'fmdd'),2))) "Wed",
MAX(DECODE(TO_CHAR(dt,'d'),'5',LPAD(TO_CHAR(dt,'fmdd'),2))) "Thu",
MAX(DECODE(TO_CHAR(dt,'d'),'6',LPAD(TO_CHAR(dt,'fmdd'),2))) "Fri",
MAX(DECODE(TO_CHAR(dt,'d'),'7',LPAD(TO_CHAR(dt,'fmdd'),2))) "Sat"
FROM ( SELECT TRUNC(SYSDATE,'y')-1+ROWNUM dt
FROM all_objects
WHERE ROWNUM <= ADD_MONTHS(TRUNC(SYSDATE,'y'),12) - TRUNC(SYSDATE,'y'))
GROUP BY TO_CHAR(dt,'fmMonthfm YYYY'), TO_CHAR( dt+1, 'iw' ))
ORDER BY TO_DATE( MONTH, 'Month YYYY' ), TO_NUMBER(week);

sql

Select All Database


select * from master..sysdatabases

Select record in Xml format


select * from Table_name for xml auto,type


See design of table


EXEC sp_help tm_task

See the File and folder of hard Drive



EXEC xp_dirtree 'Subdirectories', 'depth' , 'file'

EXEC xp_dirtree 'E:\', 2, 1