Monday, June 25, 2018

Parser error in IIS in viewing reports


Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.

Parser Error Message: Could not load file or assembly 'Microsoft.ReportViewer.WebForms, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.




Assembly Load Trace: The following information can be helpful to determine why the assembly 'Microsoft.ReportViewer.WebForms, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' could not be loaded.

WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].




Issue : missing report viewer

Solution : Download installation package from below link and install.


Below Thread gives more information



Sunday, June 24, 2018

Get the size of the folders

Below code snipet will print the size of the folders and files inside a given directory.

Dependency :


<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-io</artifactId>
<version>1.3.2</version>
</dependency>


Below id the java code

--------------------------------------------------------------------------------------------------


package folder.size;

/**
 * Dependencies
 *
 *  https://mvnrepository.com/artifact/org.apache.commons/commons-io
 */

import java.io.File;

import org.apache.commons.io.FileUtils;

public class FolderSize {
public static void main(String[] args) {
long size = FileUtils.sizeOfDirectory(new File("C:/Folder"));

System.out.println("Folder Size: " + size + " bytes");

FolderSize folderSize = new FolderSize();
folderSize.getFirstLevelChildFolderSize("C:/Folder");
}

/**
* Get the size of the directories and files inside a given directory.
*
* @param directoryName
*            Parent directory name.
*/
public void getFirstLevelChildFolderSize(String directoryName) {
File directory = new File(directoryName);

// get all the files from a directory
File[] fList = directory.listFiles();
for (File file : fList) {
if (file.isFile()) {

long size = new File(file.getAbsolutePath()).length();
// System.out.println(file.getAbsolutePath() + "=" + size);

// System.out.println(file.getAbsolutePath() + " = "
// + FileUtils.byteCountToDisplaySize(size));

System.out.println(file.getAbsolutePath() + " , "
+ FileUtils.byteCountToDisplaySize(size));
} else if (file.isDirectory()) {
long size = FileUtils.sizeOfDirectory(new File(file.getAbsolutePath()));
// System.out.println(file.getAbsolutePath() + "=" + size);

// System.out.println(file.getAbsolutePath() + " = "
// + FileUtils.byteCountToDisplaySize(size));

System.out.println(file.getAbsolutePath() + " , "
+ FileUtils.byteCountToDisplaySize(size));
}
}

}
}

Wednesday, June 20, 2018

SQL server check the status of the shrink

I have shrink database using SQL server Management Studio visual editor.

Right click database --> tasks --> Shrink --> database

Window comes and shows shrink is running. But this has been there for more than one day. So i need to check the status of the shrinking.



with below script you will get list of the commands and its status, completed percentage etc. look for command DbccFilesCompact , you will get all the details.

--------------------------------------------------------------------------------------------------

SELECT percent_complete, start_time, status, command, estimated_completion_time, cpu_time, total_elapsed_time
FROM sys.dm_exec_requests

----------------------------------------------------------------------------------------------------

As above  may give a little too large list, you can put a cross apply and get a better output as below script


----------------------------------------------------------------------------------------------------

select T.text, R.Status, R.Command, DatabaseName = db_name(R.database_id)
       , R.cpu_time, R.total_elapsed_time, R.percent_complete
from   sys.dm_exec_requests R
       cross apply sys.dm_exec_sql_text(R.sql_handle) T
order by Command

----------------------------------------------------------------------------------------------------



When i query, status was shown as "suspended".
I tried to cancel job by clicking window close button, but did not work.
So i restarted the db server and shrink the log file using the script.


----------------------------------------------------------------------------------------------------

USE [myDb]
GO
DBCC SHRINKFILE (N'myDB_log' , 0, TRUNCATEONLY)
GO

----------------------------------------------------------------------------------------------------


'myDB_log' is the logical name for the log file for the database 'myDB'

Monday, June 18, 2018

Stop Transaction Logs from Growing on a SQL Server

Problem: In a SQL server, you may have seen most of the time space becomes zero due to growth of the log.

Solution: In SQL Server, database transaction log keeps growing until you take a backup of the database. Once taken backup, log files will be truncate. It is not logical to delete transaction log files until you take a backup of the database ( mostly for production class database servers, for test environment transaction logs may not important as production).

Why ?

In a situation, database corruption or loss, you can recreate the database with restoring last database backup and restoring transaction logs on top of that with no loss.

(This is why database files and log files should be in different disks)

But in a test environment ( Other than production ) it is preferred to be automatically truncate the log files which will help to reduce the space used by the database. SQL server let us do this by changing the recovery model.

Set the recovery model = Simple

How to do 

Open SQL server Management studio --> select database --> Right click and select Properties --> Go to Option --> Change "recovery model" to Simple

you can do it in script using below

USE [master]
GO
ALTER DATABASE [myDB] SET RECOVERY SIMPLE WITH NO_WAIT
GO

You can check model with below script

SELECT name, recovery_model_desc 
   FROM sys.databases 
      WHERE name = 'myDB' ;


If Log files has grown, better to shrink after changing the recovery type.