Friday, June 12, 2015

Bind Date Time in Gridview

During development, when try to bind data to a date time control in gridview, it successfully insert data in DB from the date time control. When try to retrieve back from DB and bind it to the date time control. There is always an empty field. So here my solution.

At aspx page, add a control to hold the value and make it visible to false.

<asp:Label ID="lblDate" Text='<%#Eval("PurchaseDate", "{0:dd MMM yyyy}") %>' runat="server" Visible="false" />

When the page load or any action trigger the reload of the gridview, the RowDataBound will bound the data row by row. So that we can use RowDataBound method to bind the data from label to the date time control.
Below is the code behind snippet.

 protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
 {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                Label lblDate = (Label)e.Row.FindControl("lblDate");
                DateTimeControl dtDate = (DateTimeControl)e.Row.FindControl("PurchaseDate");

                if (!string.IsNullOrEmpty(lblDate.Text))
                {
                    dtDate.SelectedDate = Convert.ToDateTime(lblDate.Text);
                }
            }
}

Wednesday, May 13, 2015

Backup MS SQL Server

In order to ensure the database data is always goes well, so here I am to blog on how to perform the backup for MS SQL. For sure you may need to have access to the database server by using the SQL Server Management Studio. Select the database that you wish to backup and right click -> task -> backup


After the action, there will be a new window pop up and that the configuration page that how the backup to be done. There is few backup type available and in my case i would like to perform a full backup to backup the entire database. At the bottom there is a destination of the backup, if you wish to change it, you may need to remove it. For adding the custom backup destination, click on add and select the destination of the directory. 


There is more backup option available which locate at top right of the window. Select the Option, you may see the overwrite media configuration. You may able to replace the backup by select Overwrite all existing backup sets. So old the old backup file will be replace with the new backup.

After finish configure, it will start the backup process


Lastly, when the backup is finish, there will prompt a message.


Tuesday, April 28, 2015

Database is Suspect Mode

There is a time the electric blackout in my place and cause the database is unable to open. There is a (Suspect) after the database name as show as screen shot below. This know as Suspect Mode.



This issues may cause by:
  • There is not enough space available for the SQL Server to recover the database during startup.
  • The database cannot be opened due to inaccessible files or insufficient memory or disk space.
  • The database files are being held by operating system, third party backup software etc.
  • There was an unexpected SQL Server Shutdown, power failure or a hardware failure.


In order to resolve this problem, recovering is needed to access again the database. So first of all you may need a database administrator account login the MS SQL Management and click on new query button. And start the script as below:

EXEC sp_resetstatus [YourDatabaseName];
ALTER DATABASE [YourDatabaseName] SET EMERGENCY
DBCC checkdb([YourDatabaseName])
ALTER DATABASE [YourDatabaseName] SET SINGLE_USER WITH ROLLBACK IMMEDIATE
DBCC CheckDB ([YourDatabaseName], REPAIR_ALLOW_DATA_LOSS)
ALTER DATABASE [YourDatabaseName] SET MULTI_USER


Replace YourDatabaseName with your database name. In my example will be as follow.


EXEC sp_resetstatus [test_dr];
ALTER DATABASE [test_dr] SET EMERGENCY
DBCC checkdb([test_dr])
ALTER DATABASE [test_dr] SET SINGLE_USER WITH ROLLBACK IMMEDIATE
DBCC CheckDB ([test_dr], REPAIR_ALLOW_DATA_LOSS)
ALTER DATABASE [test_dr] SET MULTI_USER

Once you have done the script, click on execute query at the top. If for the first time is fail, double click again the make the script run. Then refresh your Object explorer and the (Suspect) will get rid and able to access the database again.

Microsoft SQL Server Error 926

In my development life, there is many issues coming up to resists you in development. Database is one of it,  as today I face this issue below. This error able me to start the MS SQL Management Studio but unable to see any one of the db on it. After some time of troubleshooting, finally get this issues resolve.


In order to resolve this issues, you may need another working database. Copy the MSDBDATA.mdf and MSDBLOG.ldf  from another environment machine.

By default, the files directory  will some where around here. (If you have custom path, please check your own database setting.)

C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA

In order to copy and replace both of the files, you need to stop your SQL Server Service  then only able to copy and replace both of the file.

Please make sure you make a backup before you replace the file as a safe keeping for just in-case purpose.

Once you replace the working MSDBDATA and MSDBLOG files, start the SQL Server service again.

Tuesday, April 14, 2015

My RAID 0 PC

I have 2 extra hard drive that not in use and think of increase the storage size of the PC. So that i have made a decision that to setup hard drive as RAID 0. Why i chose RAID 0 because it able to provide batter performance compare with setup hard drive as secondary hard drive. In the same time, RAID  0 also able provide redundancy which use another hard drive as recover medium.

For gaming user or hard disk resource hungry application may consider this choice without compromising the performance and space.

Below is the performance chart during copy of large file from a USB 3.0 external hard disk to local disk (raid volume). 



So make sure using the latest version of RAID driver as it give slightly increase of performance too.

Tuesday, April 7, 2015

Promoting Window Server 2012 as Domain Controller

After you have done installation of the Active Directory service on the server, you may need to so call "activate" the service and do some configuration on the server to work accordingly. This process know as DC promo.

In the top right corner, a warning label will now appear next to the task details icon. Click on this icon and select Promote this server to a domain controller. As screenshot below.


Let do a testing domain with the name of "contoso.local". For new domain controller, you may need to select Add a new forest, and you have to provide the domain name.


Specify the Forest functional Level, Domain Functional Level, whether or not it should be a DNS Server and also the DSRM administrator password. As you can see, it has selected the Global Catalog option by default and you cannot deselect it. The reason for this is that is the very first DC of the AD forest and at least one needs to be a Global Catalog .


After click on next, it will prompt a DNS delegation warning, you just have to click ok and proceed with next step which is NetBIOS name. The NetBIOS name will auto assigned and you just need to click next.


All the related folder Active Directory database, log files and SYSVOL data was left at their default locations. I will remain the same place and just click on next.


After that it will provide you a list of summary of setup as screenshot below.


Windows will perform a prerequisites check. If the user account used to promote the server does not have sufficient privileges (Schema Admin or Enterprise admin), then the installation will not be able to be completed. Either log onto another account that has the correct permissions or grant those permissions to the desired user and start over from the beginning of the promotion wizard. 


When you click Install, DNS and the GPMC are installed automatically.


After the promotion of the server to a DC finished server restart automatically. Congratulation, you have successfully install and config the domain controller.

Setup Domain Controller with Window Server 2012

First of all install the Window Server 2012 on machine. I will not show in this post as i assume you know how to do it.

After done install the Window Server 2012. The server manager will auto popup. With this manager allow you do configure all the configuration of the server. The local server menu at left is to change the local server setting such as host name, IP address and etc.



Before proceed with setup the active directory, you need to change the Server Name but do not join any domain and let it as Workgroup. Next you need to set IP address for this domain controller server with a static IP address. Without changing the IP address to static, you will face some issues during the setup of AD.



After change the host name and IP address, must restart the Window Server to take effect on the change. Once restart the server, now you may proceed with installing the AD service. Using the server manager, under dashboard, click on add role and features then it will appear a window as below. click on next.



On Installation Type page, select the first option "Role-based or Feature-based Installation". Scenario-based Installation option applied only to Remote Desktop services.


On the "Server Selection" Page, select a server from the server pool and click next.


To install AD DS, select Active Directory Domain Services in turn it will pop-up to add other AD DS related tools. Click on Add Features.


After clicking "Add Features" above, you will be able to click “Next >” as shown in the screen below.


On the "Select Features" Page, Group Policy Management feature automatically installed during the promotion. Click next.


On the "Active Directory Domain Services" page, it gives basic information about AD DS. Click Next.


On the "Confirmation" Page, You need to confirm this to continue with this configuration. It will provide you an option to export the configuration settings and also if you want the server to be restarted automatically as required.


After clicking "Install" the selected role binaries will be installed on the server.


After "Active Directory Domain Services" role binaries have been installed and now it is time to promote the server to a Domain Controller.


Until here you have successfully install the Active Directory service on the server. So next step you may need to promote this server as domain controller.