HTTP Error 500.19 - Internal Server Error

HTTP Error 500.19 - Internal Server Error




HTTP Error 500.19 - Internal Server Error

The requested page cannot be accessed because the related configuration data for the page is invalid.


Solution:

Please check if there is any url rewriting tag is there in web.config file, if exists then remove it.


Hope this will help you and save your time.

Enjoy !!!

:)

Get Time Zone list in C#

Get Time Zone list in C#


Here, it is a sample code to get time zone list in C#


string listTimeZone="";

foreach (TimeZoneInfo tzi in TimeZoneInfo.GetSystemTimeZones())
 listTimeZone += tzi.Id + " - " + tzi.DisplayName;




protected void Page_Load(object sender, EventArgs e)
        {
            var inputTime = Convert.ToDateTime("01/15/2019 04:30:00").ToUniversalTime();
 
            TimeZone localZone = TimeZone.CurrentTimeZone;

            lblMessage.Text = localZone.StandardName;

            DateTime outPutTime = inputTime.ToTimeZoneTime(localZone.StandardName);

            lblMessage.Text += "<br>" + inputTime.ToString();
            lblMessage.Text += "<br>India = " + outPutTime.ToString();


            lblMessage.Text += "<br>US Eastern Standard Time = " + inputTime.ToTimeZoneTime("US Eastern Standard Time").ToString();

        }



public static class genericDate
    {
        public static DateTime ToTimeZoneTime(this DateTime time, string timeZoneId = "Pacific Standard Time")
        {
            TimeZoneInfo tzi = TimeZoneInfo.FindSystemTimeZoneById(timeZoneId);
            return TimeZoneInfo.ConvertTimeFromUtc(time, tzi); 
        } 
    }



Hope this will help you and save your time.

Enjoy !!!

:)

Convert Json to Class in C#

Convert Json to Class in C#


Here it is a sample code to convert json data into Class object.


namespace JsonToClass
{
    class Program
    {
        static void Main(string[] args)
        {
            var jsonInput = "{ username:'myName',password:'myPass'}";
 
            var data = JsonConvert.DeserializeObject<demo>(jsonInput);
        }
    }
 
    class demo
    {
        public string username { getset; }
        public string password { getset; }
    }
}

Hope this will help you and save your time.

Enjoy !!!

:)

The transaction log for database 'dbname' is full. To find out why space in the log cannot be reused, see the log_reuse_wait_desc column in sys.databases

The transaction log for database 'dbname' is full. To find out why space in the log cannot be reused, see the log_reuse_wait_desc column in sys.databases


Issue:
InnerException: System.Data.SqlClient.SqlException (0x80131904): The transaction log for database 'dbname' is full. To find out why space in the log cannot be reused, see the log_reuse_wait_desc column in sys.databases


Analysys:

The issue says that the transaction log has reached its configured size or disk does not have sufficient space. , so we need to make space.


Solution 1:


Clear the log file and freeing disk space

Use [dbname]

Find log file name using below query and pass it in DBCC SHRINKFILE query 
Select * from sys.database_files

ALTER DATABASE [dbname] SET RECOVERY SIMPLE

DBCC SHRINKFILE ('dbname_Log', 1)

Solution 2:

Move log file on another drive

Please follow steps mentioned in below article,
http://anrorathod.blogspot.com/2018/02/how-to-move-or-change-datamdf-file-or.html


For more information you can refer, 

Troubleshoot a Full Transaction Log (SQL Server Error 9002)


https://docs.microsoft.com/en-us/sql/relational-databases/logs/troubleshoot-a-full-transaction-log-sql-server-error-9002?view=sql-server-2017

Hope this will help you and save your time.

Enjoy !!!

:)

GitExtension Settings

GitExtension Settings


 Many times I faced issue with git extensions setting, due to not proper settings it was not working properly. 

So I have listed out setting for git extension.


Editor = C:/Program Files (x86)/GitExtensions/GitExtensions.exe fileeditor
Mergetool = TortoiseMerge
Path to mergetool =  C:/Program Files/TortoiseSVN/bin/TortoiseMerge.exe
Mergetool
 command = 
C:/Program Files/TortoiseSVN/bin/TortoiseMerge.exe /base:"$BASE" /mine:"$LOCAL" /theirs:"$REMOTE" /merged:"$MERGED"
Difftool =  tmerge
Path to difftool =  C:/Program Files/TortoiseSVN/bin/TortoiseMerge.exe
Difftool command =  C:/Program Files/TortoiseSVN/bin/TortoiseMerge.exe "$LOCAL" "$REMOTE"


Hope this will help you and save your time.


Enjoy !!!

:)

Read Event Viewer logs using C#

Read Event Viewer logs using C#


 Below demonstrated code helps to read logs data from event viewer and stores in database using entity framework.

Database table

CREATE TABLE [dbo].[EventLogData](
 [Id] [int] IDENTITY(1,1) NOT NULL,
 [EventId] [nvarchar](10) NULL,
 [EventType] [nvarchar](50) NULL,
 [Site] [nvarchar](200) NULL,
 [Source] [nvarchar](500) NULL,
 [TimeGenerated] [datetime] NULL,
 [Message] [ntext] NULL,
 CONSTRAINT [PK__EventLog__3214EC07A20289BA] PRIMARY KEY CLUSTERED 
(
 [Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

Code


namespace EventLogsDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            EventLog log = new EventLog("Application");
            var entries = log.Entries.Cast<EventLogEntry>()
                                     // .Where(x => x.InstanceId == 4624)
                                     .Select(x => new
                                     {
                                         x.EventID,
                                         x.EntryType,
                                         x.Site,
                                         x.Source,
                                         x.TimeGenerated,
                                         x.Message
                                     })
                                      .ToList();

            List<EventLogData> eventLogDatas = new List<EventLogData>();
            EventLogData eventLogData;

            Console.WriteLine("Total Entries : " + entries.Count.ToString());
            foreach (var item in entries)
            {
                eventLogData = new EventLogData()
                {
                    EventId = Convert.ToString(item.EventID),
                    EventType = Convert.ToString(item.EntryType),
                    Site = Convert.ToString(item.Site),
                    Source = item.Source,
                    TimeGenerated = item.TimeGenerated,
                    Message = item.Message
                };
                eventLogDatas.Add(eventLogData);
            }

            using (var db = new EventsEntities())
            {
                db.Database.ExecuteSqlCommand("TRUNCATE TABLE EventLogData");

                db.EventLogDatas.AddRange(eventLogDatas);
                db.SaveChanges();
            }


            Console.WriteLine("Process completed. Press any key to continue...");
            Console.Read();
        }
    }
}

Hope this will help you and save your time.

Enjoy !!!

:)

Mock unit testing

Mock unit testing 



Mock unit testing is very useful for developer, but my point of view its fake unit testing, its making us foolish.
Lets see how it is...

I have created on console application in visual studio and try to explain two cases as below...

Case1

Case1: I have created Case1 folder in "UnitTestCaseProject" and write below two classes. 

namespace UnitTestCaseProject.Case1
{
    public class checkEmployee
    {
        public virtual Boolean checkEmp()
        {
            throw new NotImplementedException();
            //return true;
        }
    }
}

namespace UnitTestCaseProject.Case1
{
    public class processEmployee
    {
        public bool insertEmployee(checkEmployee objtmp)
        {
            objtmp.checkEmp();
            return true;
        }
    }
}

Case2

I have created Case2 folder in "UnitTestCaseProject" and write below three classes.

namespace UnitTestCaseProject.Case2
{
    public interface IGetDataRepository
    {
        string GetNameById(int id);
    }
}

namespace UnitTestCaseProject.Case2
{
    public class EmployeeRepository : IGetDataRepository
    {
        public string GetNameById(int id)
        {
            string name;
            if (id == 1)
            {
                name = "Excellent";
            }
            else if (id == 2)
            {
                name = "Expert";
            }
            else
            {
                name = "Not Found";
            }
            return name;
        }
    }
}

namespace UnitTestCaseProject.Case2
{
    public class Implementation1
    {
        private readonly IGetDataRepository _data;
        public Implementation1(IGetDataRepository data)
        {
            _data = data;
        }

        public string GetNameById(int id)
        {
            return _data.GetNameById(id);
        }
    }
}


Test Project

Now, I have added new test project in solution with name "UnitTestCaseProject.Test" and write unit test cases for above two cases.


I have installed "Moq" packages using manage nuget packages...

namespace UnitTestCaseProject.Test
{
    [TestClass]
    public class Case1Test
    {
        [TestMethod]
        public void insertEmployeeTestSuccess()
        {
            Mock<checkEmployee> chk = new Mock<checkEmployee>();
            chk.Setup(x => x.checkEmp()).Returns(true);

            processEmployee obje = new processEmployee();
            Assert.AreEqual(obje.insertEmployee(chk.Object), true);
        }
    }
}


namespace UnitTestCaseProject.Test
{
    [TestClass]
    public class Cast2Test
    {
        [TestMethod]
        public void TestMethod2()
        {
            var mock = new Mock<IGetDataRepository>();
            mock.Setup(p => p.GetNameById(1)).Returns("demo");
            Implementation1 home = new Implementation1(mock.Object);
            string result = home.GetNameById(1);
            Assert.AreEqual("demo", result);
        }
    }
}


While I run the above two unit test cases, it gives me success result.


Real Implementation and usage

Now, below code is actual implementation in our project "UnitTestCaseProject".

namespace UnitTestCaseProject
{
    class Program
    {
        static void Main(string[] args)
        {
            processEmployee processEmployee = new processEmployee();
            checkEmployee checkEmployee = new checkEmployee();
            var result = processEmployee.insertEmployee(checkEmployee);
            Console.WriteLine(result);
        }
    }
}



Now, if I run the project it gives me an error in actual usage, that should not give me any error while I already tested with unit test cases. So, you can see that it is not useful in our real project or application.

I suggest while you deploy project or application in Live environment, then we should write test cases with test environment.


Hope this will help you and save your time.

Enjoy !!!

:)