Tuesday, February 24, 2015

To check the query logs in SQL Server 2008 with a database compatibility mode set to 90.

To check the query logs in SQL Server 2008 with a database compatibility mode set to 90.



Method 1

SELECT SQLTEXT.text, 
       STATS.last_execution_time 
FROM   sys.dm_exec_query_stats STATS 
      CROSS apply sys.Dm_exec_sql_text(STATS.sql_handle) AS SQLTEXT 
WHERE  STATS.last_execution_time > Getdate() - 1 
ORDER  BY STATS.last_execution_time DESC 


Method 2


SELECT c.session_id, 
       s.host_name, 
       s.login_name, 
       s.status, 
       st.text, 
       s.login_time, 
       s.program_name, 
       * 
FROM   sys.dm_exec_connections c 
       INNER JOIN sys.dm_exec_sessions s 
               ON c.session_id = s.session_id 
     CROSS apply sys.Dm_exec_sql_text(most_recent_sql_handle) AS st 
ORDER  BY c.session_id 


Monday, September 15, 2014

Simple Guide : How to Rename Domain Name in Windows Server 2012?

June 10, 2013
For Server Admin who familiar with Windows Server 2000 & 2003, you maybe still remember about RENDOM utility, which is this use to rename Windows 2000 @ 2003 domain name and have to install manually.
But in Windows Server 2012 domain you don’t have to separately install “Rendom” utility.
It gets installed as part of “Active Directory Domain Services” role when you promote a server to the DC role. And It can be found here : %windir%\system32\rendom.exe.
For this time Simple Guide, I will show you all how to rename domain name in Windows Server 2012, the process is straightforward.. but as usual.. backup any necessary information @ Server before you proceed & I always advice especially to my students, please do this exercises in LAB Environment (Hyper-V).  Don’t simply take any risk by doing this is production environment unless you have to!!.
For this exercises, I’m using MCT courseware from 20410B (Installing and Configuring Windows Server 2012).
The existing domain is ADATUM.COM and I will rename it to CPX.LOCAL.
** for those who want to built your own AD and try this exercises, please refer to my previous post http://mizitechinfo.wordpress.com/2013/06/09/simple-guide-how-to-built-active-directory-in-windows-server-2012/.
So, let get started…
1 – Open your System Properties and check your existing domain name, if you see from my Windows Server 2012 system properties, my existing domain name isAdatum.com. This will be change to cpx.local in the short while.
1
2 – Next, open your Server Dashboard, go to Tools & click DNS to open DNS Manager..
2
3 – on the DNS Manager, you must create the New DNS Zone (cpx.local), this is to make sure that after whole process successfully, your member server @ Windows clients can join to new Domain name.
** to create new DNS Zone, Right Click Forward Lookup Zone, and click New Zone
3
4 – On the Welcome to the New Zone Wizard, just click Next button..
4
5 – On the Zone Type, Click Primary Zone and click Next..
5
6 – On the Active Directory Zone Replication Scope, click button To all DNS servers running on domain controllers in this domain:Adatum.com and click Next…
6
7 – In the Zone Name, key in your new Domain Name, my new Domain Name iscpx.local
7
8 – On the Dynamic Update, Click Allow only secure dynamic updates (recommended for Active Directory), and click Next…
8
9 – On the completing the New Zone Wizard, click Finish to complete the process.
9
10 – On DNS Manager, you can see my new Domain Name is listed (cpx.local)
10
11 – Next, open Command Prompt, run as administrator.. 
11
12 – In CMD, type rendom /list and press enter – this command use to generate a state file named Domainlist.xml. This file contains the current forest configuration.
12
13 – Next, open computer and browse to C:\Users\Administrator folder to get your Domainlist.xml.
13
14 – Once you see the Domainlist.xml, right click the file name & choose Edit.. I going to change the DNSname and NetBiosName in this  Domainlist.xml file.
14
15 – Once the  Domainlist.xml open, you can see there are few existing Domain name, change this existing domain name to new domain name.. refer to picture:
15
16 – once you change to new Domain name, make sure you save the  Domainlist.xml file..
16
17 – After you save the  Domainlist.xml file, close it and return to CMD. On the CMD, type rendom /showforest. This is to show the potential changes; this step does not make any changes.
17
18 – Next, type rendom /upload. This is to upload the rename instructions (Domainlist.xml) to the configuration directory partition on the domain controller holding the domain naming operations master role.
18
19 – Next, type rendom /prepare. This use to verify the readiness of each DC in the forest to carry out the rename instructions. This should contact all DC’s successfully and return no errors before proceed to next process.
19
20 – Next, type rendom /execute. This is to verifies readiness of all DC’s and then preforms the rename action on each one.
** Remember also there will be a service interruption during this process. Once the process successful, your DC Server will be restarted.
20
21
21 – Once your DC Server restarted, log in using the new Domain name as administrator.
22
22 – Next, after you successfully log in, open System Properties and check your old Domain Name is now gone.. replace by new Domain name…
23
23 – Next, open CMD again, and type gpfixup /olddns:adatum.com /newdns:cpx.local. This is to refresh all intradomain references and links to group policy objects.
24

24 – Next, type gpfixup /oldnb:lon-dc1 /newnb:cpx..
25

25 – Next, type rendom /clean. This is to remove references of the old domain name from AD.
26

26 – Next, type rendom /end. This is to unfreeze the forest configuration and allow further changes. This was frozen during the rendom /upload step.
27

27 – Next, Open DNS Manager, click your new created domain (cpx.local), here you can see your own IP listed but we still have long way to go to make sure this DNS Zone is working..
28

28 – Next, turn on your client PC, for this exercise I’m using Windows 8 as a client. Open System Properties and join to new Domain (cpx.local). in case you getting an error, don’t get scared!!.. just click OK and you Windows Security box will show up and now key in administrator and domain password and click OK (Welcome to the cpx.local domain). Refer pictures..
29

30

31

29 – After your Windows 8 restart, log in as a domain administrator.
32

30 – Once you log in, double check Windows 8 System Properties. Now yourWindows 8 successfully join in to new Domain (cpx.local).
33

31 – Now, go to the Server 2012 and open DNS Manager, you can see now yourWindows 8 Client is listed in DNS.
34

32 – You can also check in Active Directory Users & Computers that your Windows 8 Client now also listed.
35

Orait.. I done for now.. c’ya in next post!!!

Sunday, December 8, 2013

Load treeview from datasource with hardcoded root nodes on treeview (Windows Forms C#)



using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.Odbc;
using System.Data.SqlClient;


namespace ReportBuilder
{
    public partial class MainForm : Form
    {
        TreeNode parent = null;
        TreeNode child = null;
        TreeNode grandchild = null;      
        public MainForm()
        {
            InitializeComponent();
        }

        private void MainForm_Load(object sender, EventArgs e)
        {
            string groupmasterparent = "select GroupID,GroupDesc as ParentGroupDesc,ParentGroupID from aGroupMaster where AccountType='A' and ParentGroupID is null";
            SqlCommand groupmasterparentcmd = new SqlCommand(groupmasterparent, DBConnection.Getconnection());
            groupmasterparentcmd.CommandType = CommandType.Text;
            SqlDataAdapter groupmasterparentda = new SqlDataAdapter(groupmasterparentcmd);        
            DataSet ds = new DataSet();          
            groupmasterparentda.Fill(ds, "groupmasterparentdetails");          
            foreach (DataRow dr in ds.Tables["groupmasterparentdetails"].Rows)
            {              
                parent = treeView1.Nodes[0].Nodes.Add(dr["ParentGroupDesc"].ToString());
                PopulateChildinTreeView(Convert.ToInt32(dr["GroupID"].ToString()), parent);
            }          
        }
        private void PopulateChildinTreeView(int parentID, TreeNode parent)
        {                                
            string groupmaster = "select GroupID,GroupDesc,ParentGroupID from aGroupMaster where ParentGroupID="+parentID+"";          
            SqlCommand groupmastercmd = new SqlCommand(groupmaster, DBConnection.Getconnection());          
            groupmastercmd.CommandType = CommandType.Text;          
            SqlDataAdapter groupmasterda = new SqlDataAdapter(groupmastercmd);          
            DataSet ds = new DataSet();
            groupmasterda.Fill(ds, "groupmasterdetails");  
            if (ds.Tables["groupmasterdetails"].Rows.Count > 0)
            {
                foreach (DataRow drChild in ds.Tables["groupmasterdetails"].Rows)
                {
                    if (parent == null)
                        child = treeView1.Nodes[0].Nodes.Add(drChild["GroupDesc"].ToString());
                    else
                        child = parent.Nodes.Add(drChild["GroupDesc"].ToString());
                    PopulateChildinTreeView(Convert.ToInt32(drChild["GroupID"].ToString()), child);
                }              
            }
            else
                PopulateGrandChildinTreeView(parentID, parent);
        }

        private void PopulateGrandChildinTreeView(int childID, TreeNode child)
        {                      
            string accountmaster = "select * from aAccountMaster where groupid="+childID+"";          
            SqlCommand accountmastercmd = new SqlCommand(accountmaster, DBConnection.Getconnection());          
            accountmastercmd.CommandType = CommandType.Text;          
            SqlDataAdapter accountmasterda = new SqlDataAdapter(accountmastercmd);
            DataSet ds = new DataSet();          
            accountmasterda.Fill(ds, "accountmasterdetails");
            foreach (DataRow drChild in ds.Tables["accountmasterdetails"].Rows)
            {
                if (child == null)
                    grandchild = parent.Nodes.Add(drChild["AccountDesc"].ToString());
                else
                    grandchild = child.Nodes.Add(drChild["AccountDesc"].ToString());
            }
        }
    }
}

Load DeveExpress treelistview from datasource with hardcoded root nodes on treelistview (Windows Forms in C#)



using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.Odbc;
using System.Data.SqlClient;
using DevExpress.XtraTreeList;
using DevExpress.XtraTreeList.Nodes;
using DevExpress.XtraTreeList.Columns;


namespace ReportBuilder
{
    public partial class MainForm : Form
    {      
        TreeListNode rootnodeAsset = null;
        TreeListNode rootnodeLiability = null;
        TreeListNode rootnodeIncome = null;
        TreeListNode rootnodeExpense= null;
        TreeListNode ParentNode = null;
        TreeListNode ChildNode = null;
        TreeListNode GrandChildNode = null;
        public MainForm()
        {
            InitializeComponent();
        }

        private void MainForm_Load(object sender, EventArgs e)
        {
            string groupmasterparent = "select GroupID,GroupDesc as ParentGroupDesc,ParentGroupID from aGroupMaster where AccountType='A' and ParentGroupID is null";
            SqlCommand groupmasterparentcmd = new SqlCommand(groupmasterparent, DBConnection.Getconnection());
            groupmasterparentcmd.CommandType = CommandType.Text;
            SqlDataAdapter groupmasterparentda = new SqlDataAdapter(groupmasterparentcmd);        
            DataSet ds = new DataSet();          
            groupmasterparentda.Fill(ds, "groupmasterparentdetails");
            rootnodeAsset = trlstGroupMaster.AppendNode(new object[] { "Asset" }, null);
            rootnodeLiability = trlstGroupMaster.AppendNode(new object[] { "Liability" }, null);
            rootnodeIncome = trlstGroupMaster.AppendNode(new object[] { "Income" }, null);
            rootnodeExpense = trlstGroupMaster.AppendNode(new object[] { "Expense" }, null);
            foreach (DataRow dr in ds.Tables["groupmasterparentdetails"].Rows)
            {
                ParentNode = trlstGroupMaster.AppendNode(new object[] { dr["ParentGroupDesc"].ToString() }, rootnodeAsset);
                dxPopulateChildinTreeView(Convert.ToInt32(dr["GroupID"].ToString()), ParentNode);              
            }
                       
        }
        private void dxPopulateChildinTreeView(int parentID, TreeListNode ParentNode)
        {
            string groupmaster = "select GroupID,GroupDesc,ParentGroupID from aGroupMaster where ParentGroupID=" + parentID + "";
            SqlCommand groupmastercmd = new SqlCommand(groupmaster, DBConnection.Getconnection());
            groupmastercmd.CommandType = CommandType.Text;
            SqlDataAdapter groupmasterda = new SqlDataAdapter(groupmastercmd);
            DataSet ds = new DataSet();
            groupmasterda.Fill(ds, "groupmasterdetails");  
            if (ds.Tables["groupmasterdetails"].Rows.Count > 0)
            {
                foreach (DataRow drChild in ds.Tables["groupmasterdetails"].Rows)
                {
                    if (ParentNode == null)
                        ChildNode = trlstGroupMaster.AppendNode(new object[] { drChild["GroupDesc"].ToString() }, rootnodeAsset);
                    else
                        ChildNode = trlstGroupMaster.AppendNode(new object[] { drChild["GroupDesc"].ToString() }, ParentNode);
                    dxPopulateChildinTreeView(Convert.ToInt32(drChild["GroupID"].ToString()), ChildNode);
                }
            }
            else
                dxPopulateGrandChildinTreeView(parentID, ParentNode);
        }

        private void dxPopulateGrandChildinTreeView(int childID, TreeListNode ChildNode)
        {
            string accountmaster = "select * from aAccountMaster where groupid=" + childID + "";
            SqlCommand accountmastercmd = new SqlCommand(accountmaster, DBConnection.Getconnection());
            accountmastercmd.CommandType = CommandType.Text;
            SqlDataAdapter accountmasterda = new SqlDataAdapter(accountmastercmd);
            DataSet ds = new DataSet();
            accountmasterda.Fill(ds, "accountmasterdetails");
            foreach (DataRow drGrandChild in ds.Tables["accountmasterdetails"].Rows)
            {
                if (ChildNode == null)
                    GrandChildNode = trlstGroupMaster.AppendNode(new object[] { drGrandChild["AccountDesc"].ToString() }, ParentNode);
                else
                    GrandChildNode = trlstGroupMaster.AppendNode(new object[] { drGrandChild["AccountDesc"].ToString() }, ChildNode);
            }
        }
    }          
}



Saturday, March 16, 2013

Sunday, March 10, 2013

SQL Backup using Query



USE master

GO


BACKUP DATABASE [DBNAME] TO DISK N'E:\DBBackup\Backup_10032013'
WITH NOFORMAT , INIT, NAME = N'DB Full Database Backup'SKIP, NOREWIND, NOUNLOAD, STATS = 10  

GO 

Tuesday, January 29, 2013

How to hide a Contentpane or any Controls in FormAlpha on a Button click event of FormBeta which loads as a dialog box on top of FormAlpha


Two steps are needed:
First, Form Alpha needs a public Fucntion called "hidePane()" whose sole purpose is to hide the Pane.
Second, Form Beta needs a reference to Form Alpha. I asume that Alpha creates generates Beta and shows it. In this case give Beta a constructor that takes a FormAlpha as parameter:
//Variable to store wich form created this form
FormAlpha creatorForm;

public FormBeta (FormAlpha Creator){
  InitializeComponent();
  creatorForm = Creator;
}
Instead of using the normal empty constructor to create FormBeta:
Form otherForm = new FormBeta();
otherForm.show();
use the newly created one and give it a Reference to Alpha with "this":
Form otherForm = new FormBeta(this);
otherForm.Show();
now all your ButtonClick even has to do is call the hidePanle():
creatorForm.hidePanel();
P.S. if you want to be able to unhide he Panel as well, we may have to change step 1 a little.