Thursday, April 25, 2013

Version control of sql

Project Description
monitor sql server processes and jobs, analyze performance, analyse system, object version control, view executing sql query, kill process / job, object explorer, database shrink/log truncate/backup/detach/attach.
it uses linq and requires .net 4.0 (client profile), only support SQL Server 2005/2008/2008R2/2012, not for 2000, sorry :(
the implementation is quick, pretty straight forward, but I try to maintain the logic and make the job done.
There is an article about this project at code project: http://www.codeproject.com/KB/database/sqlmon.aspx
And there is the second article also at code project: http://www.codeproject.com/KB/database/sqlmonitor.aspx

Why
ok, I have to admit that I got bored so I just want to make something. It looks like I am reinventing a wheel(duplicating part of SQL Server Management Studio?), mmm, actually, I don't think so. I address something here that do not exist in SQL Server Management Studio at all, at least not in 2012RC0.

Target
Step 1: a real monitor, keep tracking sql server actitivities(sql execution, cpu consumption, disk space etc), alert on customized notifications.
Step 2: support oracle/mysql/firebird/postgresql etc.
Step 3: accessible on any client (including mobile phones).

Features

To Do
see Issue Tracker

Screen Shots

0. All New Health Monitor


1. Performance Graph


Monitor Multiple Servers / Databases

Popup/Dock Performance Graph



2. Object Explorer


3. Object Version Control


4. Version Compare


5. Activities
 

6.Process Visualizer

7. Analysis - Database


8. Analysis - Execution


9.Analysis Logic Fault



9. Alerts


10. Alerts - Empty Table


Wednesday, April 24, 2013

HTML to PDF Conversion

Html to Pdf conversion in asp.net c# i searched on google html to pdf conversion, but i found a very few and most of them are not working properly. so i decided to develop a very small code for conversion. iTextSharp utility gives us control to perform most of the operations on pdf files.

1- download ITextSharp.dll

2- add itextsharp.dll reference in your project

3- include following libraries in c# code

Code:
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using iTextSharp.text;
using iTextSharp.text.html;
using iTextSharp.text.pdf;
using iTextSharp.text.html.simpleparser;
using System.IO;
using System.util;
using System.Net;
using System.Xml;

4- Generate pdf file from html
Code:
protected void btn_submit_Click(object sender, EventArgs e)
    {
        using (StreamReader reader = new StreamReader(Server.MapPath("~") + "/App_Data/test.html"))
        {
            String line = reader.ReadToEnd();
            Text2PDF(line);
        }
    }

    protected void Text2PDF(string PDFText)
    {
        //HttpContext context = HttpContext.Current;
        StringReader reader = new StringReader(PDFText);

        //Create PDF document
        Document document = new Document(PageSize.A4);
        HTMLWorker parser = new HTMLWorker(document);

        string PDF_FileName = Server.MapPath("~") + "/App_Data/PDF_File.pdf";
        PdfWriter.GetInstance(document, new FileStream(PDF_FileName, FileMode.Create));
        document.Open();

        try
        {
            parser.Parse(reader);
        }
        catch (Exception ex)
        {
            //Display parser errors in PDF.
            Paragraph paragraph = new Paragraph("Error!" + ex.Message);
            Chunk text = paragraph.Chunks[0] as Chunk;
            if (text != null)
            {
                text.Font.Color = BaseColor.RED;
            }
            document.Add(paragraph);
        }
        finally
        {
            document.Close();
            DownLoadPdf(PDF_FileName);
        }
    }

in above code, my html file already exist in app_data, you can modify your code either by uploading file or by a fixed location.
in finally the function DownLoadPdf(PDF_FileName) download the newly generated pdf to client.

5- download pdf file
Code:
private void DownLoadPdf(string PDF_FileName)
    {
        WebClient client = new WebClient();
        Byte[] buffer = client.DownloadData(PDF_FileName);
        Response.ContentType = "application/pdf";
        Response.AddHeader("content-length", buffer.Length.ToString());
        Response.BinaryWrite(buffer);
    }

the code is really simple, but it does not support external css and images.

this code successfully parse the red color and bold property on below line
Code:
<font color='red'><b>www.dotnetobject.com</b></font>

BackUp Sql2008

Here's how to setup automatic daily backups for SQL Server 2008 databases:
  1. Open Microsoft SQL Server Management Studio.
  2. Expand the database server.
  3. Expand the Management folder.
  4. Right-click Maintenance Plans and select Maintenance Plan Wizard. This launches the wizard and you can now step through and create a plan customized to meet your maintenance requirements.
  5. Click 'Next' button, then name your Maintenance Plan and give description.  Select the radio button that says "Single schedule for the entire plan or no schedule".
  6. Under Schedule,  click on the 'Change' button.  This brings up the Job Schedule Properties form. In the Frequency section, change Occurs to 'Daily', and then click 'OK.
  7. Click 'Next' button, then check the box next to "Back Up Database (Full)", then click 'Next'.
  8. Click 'Next' button again, then select one or more of your Databases to be backed up using the Database(s) drop down box. Make any additional settings and then click 'Next'.
  9. On the Select Report Options form, click the 'Next' button once again.
  10. Then click the 'Finish' button to complete the wizard.
  11. The Maintenance Plan Wizard will run and should complete successfully.  Click the 'Close' button.
  12. You should now see the database backup maintenance plan you just created underneath the Maintenance Plans folder in SQL Server Management Studio.