Category: C#

  • How to use CLR function at SQL Server?

    Creating a CLR function in SQL Server involves the following steps: 1. Define the function as a static method of a class in a language supported by the .NET Framework 2. Register the assembly in SQL Server by using the CREATE ASSEMBLY statement 3. Create the function that references the registered assembly by using the…

  • How to enable “Windows Authentication” for your websites?

    There are few things which we need to do before access the website using windows authentication. Web.config: Add or replace existing Authentication Tag IIS Express with Visual Studio: Click on your project in the Solution Explorer to select the project. Open Properties pane suing F4. In the Properties pane for your project: a) Set “Anonymous…

  • Remove Empty Directories using c#

    private static void DeleteEmptyDirectory(string startLocation) { foreach (var directory in Directory.GetDirectories(startLocation)) { DeleteEmptyDirectory(directory); if (Directory.GetFiles(directory).Length == 0 && Directory.GetDirectories(directory).Length == 0) { Directory.Delete(directory, false); } } }

  • Cannot load Counter Name data because an invalid index ” was read from the registry

    Cannot load Counter Name data because an invalid index ” was read from the registry When we are trying to read system performance counters, some time we will get this type of error on machines. “Cannot load Counter Name data because an invalid index ” was read from the registry” To fix the issue: Click…

  • RESTSHARP: GET / POST/ DOWNLOAD and UPLOAD with and without Authentication

    //GET: var client = new RestClient(“http://www.example.com/”); client.Authenticator = new HttpBasicAuthenticator(“username”, “password”); var request = new RestRequest(URI, Method.GET); request.AddQueryParameter(“id”, customid); var queryResult = client.Execute(request).Content; //POST: var client = new RestClient(“http://www.example.com/”); client.Authenticator = new HttpBasicAuthenticator(“username”, “password”); var request = new RestRequest(URI, Method.POST); request.RequestFormat = DataFormat.Json; request.AddQueryParameter(“id”, customid); request.AddBody(Parameters); IRestResponse response = client.Execute(request); //DOWNLOAD FILE: var client =…

  • Cannot load MVC4 Web project in VS 2017 or VS 2019

    I have a web project, it could load fine in VS15, but in VS2019 it’s failing, saying the project is incompatible. The migration report contains the following message: ========== .csproj: The application which this project type is based on was not found. Please try this link for further information: http://go.microsoft.com/fwlink/?LinkID=299083&projecttype=E3E379DF-F4C6-4180-9B81-6769533ABE47 To resolve it: 1. Open…

  • How to read DBF to Datatable

    [csharp] OleDbConnection oConn = new OleDbConnection(@”Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\Temp;Extended Properties=dBase III”); OleDbCommand command = new OleDbCommand(“SELECT * FROM Test.DBF”, oConn); oConn.Open(); DataTable dt = new DataTable(); dt.Load(command.ExecuteReader()); oConn.Close(); [/csharp]

  • Missing Windows Authentication Feature IIS and Windows 10

    If you have windows 10 Home or SL version when might be you are unable to see Windows Authentication under IIS options when installing. To enable “Windows Authentication” either you need to upgrade the OS to Pro version or you can run this command to enable it. C:\WINDOWS\system32>dism /online /norestart /add-package:%SystemRoot%\servicing\Packages\Microsoft-Windows-IIS-WebServer-AddOn-2-Package~31bf3856ad364e35~amd64~~10.0.17134.1.mum The file name will…

  • How to speed up database and table listing in Management Studio

    In SQL Management Studio, select the “Databases” node in the Object Explorer. Then, click View –> Object Explorer Details. Right click on one of the column headers and uncheck all of the columns besides “Name”. These columns are slowing down the process of expanding the database list.

  • How to get list of all always encrypted columns in SQL Server

    We do have “Always encrypted” feature in SQL 2016 and later versions, from this feature we can encrypt the column data instead of encrypting whole database.  Sensitive data like credit card numbers, SSN. We need to prepare a list of encrypted columns at some where to track for future. Without tracking anywhere in the documents…