Lazy DBA

The philosophy behind the name is: A lazy dba is a SMART dba. A lazy dba is too lazy to look after databases manually , so they ‘ll write their own scripts to automate oracle server activities. A lazy dba doesn’t want to be woken up in the middle of the night by a ring, so they actively monitor their databases to make sure that there are no surprises.

You can download some scripts from here... Don't use this scripts in production 
environment. Please test it and use it

1. freeSpace

2. dbGrowth


Checking if all the character in a string are capital in SQL

CREATE FUNCTION CheckIfAllCaps (@StringToCheck VARCHAR(500))
RETURNS bit
AS
BEGIN
DECLARE @return BIT
DECLARE @position INT

SET @position = 1

WHILE @position <= DATALENGTH(@StringToCheck)
BEGIN
IF ASCII(SUBSTRINGTOCHECK(@StringToCheck, @position, 1)) BETWEEN 65 AND 90
SELECT @return = 0
ELSE
SELECT @return = 1

IF @Return <> 1
SET @position = @position + 1
ELSE
GOTO ExitUDF
END

ExitUDF:
RETURN @return

END



imports crystaldecisions.shared
imports system.data
imports system.data.sqlclient

Dim strrptname As String
Dim rptdocu As New CrystalDecisions.CrystalReports.Engine.ReportDocument

Dim param As New SqlParameter
Dim _cmd As New SqlCommand
Dim _adp As New SqlDataAdapter
Dim ds1 As New DataSet

‘…………………………….Select Stored proceedure……………..
_cmd.CommandText = “rpt_namewise”
_cmd.CommandType = CommandType.StoredProcedure
_cmd.Connection = _con
_con.Open()
‘ …………………………………………………………….Select from combo box………….
If ComboBox1.SelectedItem <> “” Then
param = New SqlParameter(“@name”, ComboBox1.SelectedItem)
_cmd.Parameters.Add(param)
Else
param = New SqlParameter(“@name”, “”)
_cmd.Parameters.Add(param)
End If
_adp.SelectCommand = _cmd
_adp.Fill(ds1)
_con.Close()
_adp.Dispose()
_cmd.Dispose()

strrptname = “CrystalReport1.rpt”
Dim strrptpath As String
strrptpath = Application.StartupPath & “\” & strrptname
// ‘strrptpath = “D:\projects\Chandrika\Chandrika\CrystalReport1.rpt”
If Not IO.File.Exists(strrptpath) Then
Throw (New Exception(“unable to find reprt path”))
End If
rptdocu.Load(strrptpath)
rptdocu.SetDataSource(ds1)
guest_name_rpt_viewer.Show()
guest_name_rpt_viewer.ShowRefreshButton = False
guest_name_rpt_viewer.ShowCloseButton = False
guest_name_rpt_viewer.ReportSource = rptdocu

‘……………………………………To pass parameter to Report………………….
Dim f1 As New ParameterField
Dim val1 As New ParameterDiscreteValue
f1 = guest_name_rpt_viewer.ParameterFieldInfo(0)
val1.Value = ComboBox1.SelectedItem
f1.CurrentValues.Add(val1)
rptdocu.Refresh()
ds1.Tables(0).Reset()
ComboBox1.SelectedIndex = -1
_adp.Dispose()

…………………………………………………………………………………………………………………….

INNER JOIN

SELECT dbo.Room_Details_.room_no, dbo.Room_Details_.room_issue_flag, dbo.Room_Type_.room_type, dbo.Room_Type_.room_tariff,
dbo.Room_Type_.room_ext, dbo.Room_Type_.room_desc
FROM dbo.Room_Details_ INNER JOIN
dbo.Room_Type_ ON dbo.Room_Details_.room_type_id = dbo.Room_Type_.room_type_id
WHERE (dbo.Room_Details_.room_issue_flag = ‘yes’)

Get & Set Cookies


void SubmitButton_Click(Object Src, EventArgs E) {
msg.Text =SetCookie(cookname.Text, cookvalue.Text, Convert.ToInt32(cookexpiry.Text)).ToString();
msg.Text+=”. Expires: ” + Response.Cookies[cookname.Text].Expires.ToString();
}
void SubmitButton_Click2(Object Src, EventArgs E) {
msg.Text =GetCookie(cookname.Text);
}
public bool SetCookie(string cookiename, string cookievalue ,int iDaysToExpire)
{
try{
HttpCookie objCookie = new HttpCookie(cookiename);
Response.Cookies.Clear();
Response.Cookies.Add(objCookie);
objCookie.Values.Add(cookiename,cookievalue);
DateTime dtExpiry = DateTime.Now.AddDays(iDaysToExpire);
Response.Cookies[cookiename].Expires =dtExpiry;
}
catch( Exception e){
return false;
}
return true;
}
public string GetCookie(string cookiename){
string cookyval=”";
try{
cookyval= Request.Cookies[cookiename].Value;
}
catch(Exception e){
cookyval=”";
}
return cookyval;
}

I got most of the scripts from the Net. So I thought I will just 
share it. If any probs let me know I shall remove it...
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.