Tuesday, November 23, 2010

How to display html page inside an iFrame via link

Displaying a page inside iFrame via link is as simple as setting Target property of a link to the iframe name. The important part is to make sure iframe has both "id" and "name" attributes.


<a href="http://elena-sqldba.blogspot.com" target="myFrame">Elena's Blog</a>

<iframe id="myFrame" runat="server" width="500" name="myFrame">

</iframe>

How to create a slide show of external pages inside a DIV

The code below unables you to display various external pages inside a DIV and switching them every 15 seconds


First add a DIV to your html page


<div id="contentarea"></div>


Then save jquery.js file in the dame directory as your html page and add reference to jquery to the head section of your page:


<script type="text/javascript" src="jquery.js"></script>


Then add the following script to the head section:


<script type="text/javascript">
<!--

// Place the urls in this array
var urls = new Array("page1.html", "http://elena-sqldba.blogspot.com", "http://www.google.com");
// Set the number of seconds you want to view each page
var viewfor = 15;
var mark=1;


$(document).ready(function(){
initSrc();
});

function changeurl(){
ajaxpage(urls[mark], 'contentarea');
mark+=1;// increments the mark variable (array element)
if (mark==urls.length){
mark=0;// returns to urls[0] at the end of the array count
}
}


function initSrc(){
ajaxpage(urls[0], 'contentarea');
window.setInterval("changeurl()", viewfor * 1000);
}


function ajaxpage(url, containerid){
var page_request = false
if (window.XMLHttpRequest) // if Mozilla, Safari etc
page_request = new XMLHttpRequest()
else if (window.ActiveXObject){ // if IE
try {
page_request = new ActiveXObject("Msxml2.XMLHTTP")
}
catch (e){
try{
page_request = new ActiveXObject("Microsoft.XMLHTTP")
}
catch (e){}
}
}
else
return false

page_request.onreadystatechange=function(){
loadpage(page_request, containerid)
}

page_request.open('GET', url, true)
page_request.send(null)

}

function loadpage(page_request, containerid){
if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1)){
var divElement = document.getElementById(containerid);
divElement.innerHTML = '';

try {
divElement.innerHTML = page_request.responseText;
}
catch (e) {
// IE fails unless we wrap the string in another element.
var wrappingElement = document.createElement('div');
wrappingElement.innerHTML = page_request.responseText;
divElement.appendChild(wrappingElement);
}
} //end if
}
// -->
</script>

How to load external pages into a DIV

Loading external html pages into a DIV without having to reload the browser or using iFrames is possible using AJAX and JQuery.

First add a DIV to your html page


<div id="contentarea"></div>


Then save jquery.js file in the dame directory as your html page and add reference to jquery to the head section of your page:


<script type="text/javascript" src="jquery.js"></script>


Then add the following script to the head section:


<script type="text/javascript">
<!--

$(document).ready(function(){
ajaxpage("http://elena-sqldba.blogspot.com", 'contentarea');
});


function ajaxpage(url, containerid){
var page_request = false
if (window.XMLHttpRequest) // if Mozilla, Safari etc
page_request = new XMLHttpRequest()
else if (window.ActiveXObject){ // if IE
try {
page_request = new ActiveXObject("Msxml2.XMLHTTP")
}
catch (e){
try{
page_request = new ActiveXObject("Microsoft.XMLHTTP")
}
catch (e){}
}
}
else
return false

page_request.onreadystatechange=function(){
loadpage(page_request, containerid)
}

page_request.open('GET', url, true)
page_request.send(null)

}

function loadpage(page_request, containerid){
if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1)){
var divElement = document.getElementById(containerid);
divElement.innerHTML = '';

try {
divElement.innerHTML = page_request.responseText;
}
catch (e) {
// IE fails unless we wrap the string in another element.
var wrappingElement = document.createElement('div');
wrappingElement.innerHTML = page_request.responseText;
divElement.appendChild(wrappingElement);
}
} //end if
}



// -->
</script>

Tuesday, November 16, 2010

SQL Server DBA Duties

DAILY

Action: Check Network Connectivity
Reason: To check that hardware & server is up.
To check that IP address & name have not been changed.
Gives early warning if server fails.
Checks IP address & name resolution (sometimes a problem with wins, dns, lmhosts).
Method: 1. Ping sql servers every 15 mins with IP Sentry.
2. Use batch file to ping servers.
3. Use a server monitoring tool.

Action: Check SQL services
Reason: To check that SQL server is available.
To check MSSQLserver & SQLexecutive/agent, DTS services are running.
To check that we can connect.
Method: SEM:
Green lights if SEM, or connect to each server by clicking on the ‘+’ for each server & open sql executive.

Action: Check Scheduled Tasks/ Jobs
Reason: Backups, DBCC checks, etc. are run overnight as scheduled tasks.
Method: SEM: Highlight server, servers | scheduled tasks

Action: Check dba_tools..scheduledtasklog
Reason: If get a failed scheduled task.
Some DBA’s create an error log table, which gives more detail on errors during task execution
Method: SEM: Open ISQL/W, Select * from dba_tools..scheduledtasklog.

Action: Check DBCC output
Reason: DBCC commands check DB integrity & consistency.
Finds errors in the structure of the server & databases.
If more than the usual ‘msg’ string errors, check BOL.
Method: Create desktop or folder shortcuts to point to the dbcc output text files.
Check date when checks done.

Action: Check Hard Disk Space
Reason: If system drives run low they crash.
Backup devices expand dynamically & will fail if insufficient space.
Need to know which partition is the system & which partition holds the backup devices.
Method: Windows explorer: Check drive properties
SEM: Check database devices, even if automatic.
ISQL/W: Create stored procedure or batch file, using xp_fixeddrives for each server.

Action: Check Database & Transaction Log Space
Reason: If DB or txn log space runs out, then transactions will fail. Ver 6.5
Method: SEM: Databases x2 click the DB
ISQL/W: sp_spaceused
www.SQLserverPortal.com
3rd party tools for SQL server

Action: Check Event Logs
Reason: OS errors are logged here & some SQL errors are logged here.
OS & SQL usually warns you before a problem becomes critical.
Method: Control panel, admin tools\event viewer\

Action: Check SQL Error Logs
Reason: SQL errors are logged here, SQL usually warns you before a problem becomes critical.
Method: SEM: servers | error log, scroll to bottom (ctrl+end) = most recent.
If get errors, tap in number into BOL.

WEEKLY

Action: Save all server configuration info.
Reason: You need more than just the db backup to rebuild a SQL server.
Method: ISQL/W: Create stored procedures to get config info. etc & output to txt files.

MONTHLY



Action: Do a test restore of a db backup
Reason: Sometimes backups don’t work eg due to errors found by DBCC commands.
Method: Create a test device, restore from tape to a bkup device, restore, then run DBCC checks on it.

How to modify Desktop Wallpaper using VBScript

From my experience, the best way to change Desktop wallpaper is via vbs file.

below is the code for the vbs file that assumes path to the wallpaper will be paaed as an argument to the file below:


Set oShell = CreateObject("WScript.Shell")
Set oSHApp = CreateObject("Shell.Application")

if WScript.Arguments.Count > 0 then

'Set Wallpaper path
sWallPaper = WScript.Arguments(0)

' Update Wallpaper in registry
oShell.RegWrite "HKCU\Control Panel\Desktop\Wallpaper", sWallPaper

'Refresh Screen by running Control Panel application.
'If the application is already open, it will activate the running instance.
oSHApp.ControlPanelItem cstr("desk.cpl")

' Loop and wait until Display Properties is loaded.
Do Until oShell.AppActivate ("Display Properties")
Loop
oShell.SendKeys "{DOWN}{UP}{TAB 3}~"
end if



The code above works like a charm, I find it to be a lot more efficient than running a batch file with the following code, which often does not refresh the Desktop after modifying the registry:


reg add "HKCU\Control Panel\Desktop" /v Wallpaper /t REG_SZ /d %1 /f
RUNDLL32.exe user32.dll,UpdatePerUserSystemParameters