Sunday, November 21, 2021

CSS form action selector

 Only recently I got to know that we can actually style form action. The trick is to use body with form action as shown below. Even though  have used the class name id names can also be used.


body form[action="/SomeURL/DoSearch/"] .className {

    display: none !important;

    visibility:hidden !important;

}

Cheers,

Samitha

Sunday, November 14, 2021

Windows 2019 Server MSSQL Error 'The underlying provider failed on Open'

 If you are trying to migrate your .Net applications to a Windows 2019 Server you will most likely to encounter   MSSQL Error 'The underlying provider failed on Open'.

This can be fixed by Defining a new Windows Firewall rule for SQL Server (and for port 1433) on the server machine.


Cheers,

Samitha

Sunday, October 31, 2021

use ADO.NET via Context.Database

The DbContext.Database property allows us to perform ADO.NET as sown below. 

 //Execute Reader

    using (var ctx= new DatabaseContext())
    using (var cmd= ctx.Database.GetDbConnection().CreateCommand())
    {
        cmd.CommandText = "SELECT * From Table1";
        cmd.Database.OpenConnection();
        using (var result = command.ExecuteReader())
        {
            // do something with result
        }
    } 


//Execute SP


using (var ctx= new DatabaseContext())
    using (var cmd= ctx.Database.GetDbConnection().CreateCommand())
    {
               cmd.CommandText = "dbo.someSP"
                _dataContext.Connection.Open()
                cmd.CommandType = CommandType.StoredProcedure

                Dim param As DbParameter = command.CreateParameter()
                param.DbType = DbType.Int16
                param.ParameterName = "@param1"
                param.Value = 'value1"
                cmd.Parameters.Add(param)

                param = cmd.CreateParameter()
                param.DbType = DbType.DateTime
                param.ParameterName = "@param2"
                param.Value = "value2"
                cmd.Parameters.Add(param)

                cmd.ExecuteNonQuery()
                _dataContext.Connection.Close()
        }
    } 


Cheers,

Samita

Sunday, October 17, 2021

find second DIV of the same class

If you need a CSS selector that can be used to find the 2nd DIV of  among several DIVs with the same class, CSS3 provides nth-of-type(n) selector as displayed below.

.row:nth-of-type(2) {


}


Cheers,

Samitha

Sunday, October 3, 2021

SQL sever 2014 compatibility issue when TLS 1.0 and TLS 1.1 is turned off

As there has been several vulnerabilities of  TLS 1.0 and TLS 1.1 it is turned off by default,  even though SQL latest releases supports this SQL 2014 need to be Upgraded SQL Server and the client components to  handle TLS 1..

This link further describes the issue and you will need to inset the relevant service pack for SQL 2014 (2014 SP2 and 2014 SP3.)

 

 

Cheers

Samitha



Saturday, September 4, 2021

Converting ICollection to List

 

We can use the System.Linq namespace to convert ICollection<T> to List<T>    as dsiplays below.

//class definitions

public class Students
{
    public ICollection<Courses> Courses{get;set;}
}

public class Courses
{
    public ICollection<Students> Students{get;set;}
}

//end class definition

//create the List

using System.Linq; 


List<Students> listOfStudents= lstStudents.OfType<Students>().ToList();



cheers,

Samitha

Sunday, August 22, 2021

numeric textbox (first number can't be 0)

 I wanted to validate a textbox with a number not starting with zero. For this I used Regex as displayed below.

       Regex reg = null;
       reg = new System.Text.RegularExpressions.Regex("^[1-9]\d*$")
       return reg.IsMatch(str);

Cheers

Samitha