The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.

System.Net.WebException: The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.


I got below error while calling web api on https and found the solution.

Error


System.Net.WebException: The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.

  

Solution

I solved this error by adding this line before calling the web method:

System.Net.ServicePointManager.ServerCertificateValidationCallback = (senderX, certificate, chain, sslPolicyErrors) => { return true; };


Hope this will help you and save your time.

Enjoy !!!

:)

IQueryable - Value cannot be null. Parameter name: property

Value cannot be null.

Parameter name: property


I got below error while I called orderby with IQueryable,

Error


Value cannot be null.
Parameter name: property

StackTrace:
.... OrderBy[T](IQueryable`1 query, String memberName, String direction) ....

I searched on many sites but did not get solution, then I start trial and run method on code. Finally I found that it was my silly mistake, 

Solution


SQL column name and what you passing in code should be same, its case sensitive

I was passing : countryName
SQL Column name: CountryName


Hope this will help you and save your time.

Enjoy !!!

:)

Create and Publish own nuget package

Create and Publish own nuget package


First create class library project, here I have created "DemoApp" project.


Generate the initial manifest  


Open a command prompt and navigate to the project folder containing DemoApp.csproj file.

Run the following command: 

nuget spec DemoApp.csproj

By specifying a project, NuGet creates a manifest that matches the name of the project, in this case DemoApp.nuspec. It also include replacement tokens in the manifest.

Open DemoApp.nuspec in a text editor to examine its contents and udpate



Create Package


From a command prompt in the folder containing your .nuspec file, run the command 

nuget pack

NuGet generates a .nupkg file in the form of identifier-version.nupkg, which you'll find in the current folder.



Publish with nuget push


nuget push DemoApp.1.0.0.nupkg APIKey-GetFrom-Nuget-Account -Source https://api.nuget.org/v3/index.json




Hope this will help you and save your time.

Enjoy !!!

:)

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 !!!

:)