Posts

Showing posts from 2019

Donate

Return Multiple Values From C# Asynchronous Function

Good evening fellow developers! I have a simple application that queries the database and returns list of employees and list of their dependents. Since I've just started learning async programming, I wonder if I could return multiple values for an asynchronous function or method. The initial solution that I have is to create a view model class that has two properties specifically list of employees and list of dependents. And this view model class will be the return type of the function. After reading through the docs, it's possible to return multiple values using System.ValueTuple namespace. If the target framework of the project is 4.6.2 and below, you need to add the System.ValueTuple NuGet package using NuGet Console Manager or add the package using Manage NuGet Package tool. For now, lets install the package using console manager. Install-Package "System.ValueTuple" Next is to modify the existing method to return multiple values using System.ValueTuple. pr

SQL Server : Login Success But “The database [dbName] is not accessible.” After Domain Migration Using New Domain User

Image
Recently, our systems administrator has just finished migrating our workstations from an old domain to a new domain. But this caused an issue wherein most of the databases are not accessible. I've done several workarounds from stackoverflow and non of them worked. The solution that worked is to add my new domain user to the databases using SQL Server Authentication (sa) and set my new domain user as dbOwner.

How Get Total Number Of Rows From SQLDataReader Object Using C#

Good Evening Gents! In the office, we were using SQLDataReader class to read from SQL Server database in a straight-forward manner. The SQLDataReader has several properties that are commonly used such as HasRows and FieldCount. However in one of my task, I want to retrieve the total number of rows returned from the SQLDataReader object and there's no such property that support this. Doing some search led me to this link How to get number of rows using SqlDataReader in C# . The one that worked for me was the answer using select @@ROWCOUNT query. I modified his answer by writing my own method that will accept a List of SQLParameters given that the original query requires parameters. private static void GetTotalRowCount( string query, string connectionString, ref int totalRows, List<SqlParameter> sqlParameters) { try { using ( var sqlCon = new SqlConnection(connectionString)) { sqlCon.Open(); var cmd = sqlCon.CreateCommand(); cmd.CommandText = q

This Site Can’t Provide a Secure Connection Localhost Sent An Invalid Response In ASP Classic Website

Good afternoon fellow programmers! In the event that you added an ASP Classic site to Visual Studio and when you debug or run the site, it produced an error such as "This site can’t provide a secure connection localhost sent an invalid response. Try running Windows Network Diagnostics. ERR_SSL_PROTOCOL_ERROR". The fix to this error is to comment or remove the rewrite rule in web.config. A sample rewrite node looks like this in web.config. <?xml version="1.0"?> <configuration> <system.webServer> <!--<rewrite> <rules> <rule name="Redirect to HTTPs" stopProcessing="true"> <match url="(.*)"/> <conditions> <add input="{HTTPS}" pattern="^OFF$"/> </conditions> <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="SeeOther"/>

Response Buffer Limit Exceeded. Execution of the ASP Page Caused The Response Buffer To Exceed Its Configured Limit

Good evening fellow developers! I've been given a project to rewrite an existing ASP Classic Website written in VBScript to ASP.NET MVC. For now, I'm on research stage and familiarization of the existing modules and page functionalities. The site is fully functional but some of the pages rendered an error called "Response Buffer Limit Exceeded". After doing some google search, the solution that worked for me is to set the Response Buffer of the page to false right after Language declaration. <%@ LANGUAGE = "VBSCRIPT" %> <% Response.Buffer = False %> Reference: Response Buffer Limit Exceeded Cheers! :)

Visual Studio And WPF Menu Items Are Left Aligned Instead Of Right Aligned

Image
Hello, We noticed lately that our WPF Projects menu items and Visual Studio menu items are left aligned rather than right aligned. However, not all desktop were affected by this issue. Further research led me here Windows 10 Drop-Down Menus Are Aligned To The Left in which you have to execute a shell command shell:::{80F3F1D5-FECA-45F3-BC32-752C152E456E} via Windows + R command. This will open the Tablet PC Settings with Right-Handed radio button checked. Changing it to Left-Handed then Apply will change the menu items alignment to the right. Visual Studio Menu Items Are Now Right Aligned

Parse And Replace Element Attribute Value Of Script Template Using jQuery

Good afternoon fellow programmers! I recently have a task to load a Script template that contains HTML markup to a page dynamically. But before loading the template, I need to change the attribute values of certain elements such as id and name. However, reading the template object made it difficult for me to convert it to an HTML object so I can traverse and manipulate the DOM. After doing research and some experiments, I found the solution presented below on how to read the value of a Script template and be able to use jQuery methods to traverse and update the DOM elements. Sample Script Template To Load In A Page <script type= "text/html" id= "templateGroup" > <div name= 'divChildSkill_' class= "col-md-12" id= "divChildSkill_" > <div class= "col-md-12" > <div class= "col-md-6" > <div class= "col-md-4" > <label id= "anchorLabel" >&l

XmlDataProvider With TwoWay Binding In WPF

Hello, Here's a simple example of two-way binding in WPF using XMLDataProvider. This post is taken from John Papa's example in MSDN magazine years ago but with minor errors. The XMLDataProvider markup has color values and is declared inside Window.Resources node. <Window.Resources> <XmlDataProvider x:Key= "MoreColors" > <x:XData> <colors xmlns= '' > <color name= "pink" /> <color name= "white" /> <color name= "black" /> <color name= "cyan" /> <color name= "gray" /> <color name= "magenta" /> </colors> </x:XData> </XmlDataProvider> </Window.Resources> The Textbox control's Text Text property binding has been set to TwoWay so when you enter a color name it will be added as a ListBox Item. <Grid> <StackPanel> <TextBlock Width= "248" Height= "24"

Bootstrap Table Footer Data Footer Formatter Not Computing Correctly On Multiple Columns

Image
Good Afternoon! I recently faced a minor bug in Bootstrap Table by Wenzhixin using a single data-footer-formatter for four columns. I expected that this will compute the column values but the expected result shows that all columns total are zero. Bootstrap Table <table id= "tblBillingReport" class= "TableBorderCollapse table-striped " data-toggle= "table" data-search= "true" data-show-columns= "false" data-advanced-search= "false" data-id-table= "advancedTable" data-show-export= "true" data-toolbar= "#toolbar" data-click-to- select = "true" data-unique-id= "objectID" data-cookie= "true" data-show-footer= "true" data-height= "700" data-cookie-id-table= "tblBillingReportID" > <thead> <tr style= "background-color: #FFFFFF;" > <th dat

Export SQL Server Varbinary Or Blob To Disk Using C#

Image
Good evening Gents! I was given a task to export 100+GB of files from an MSSQL DB of which these files are saved in a table using Varbinary/Blob column. I've made some spike applications using BCP and .NET CLR but to no avail all the spike applications don't work since I don't have full permission to the database. The only solution that work for me was using the OLE Automation Procedures. So in order to export files from Blob, I'll present the steps below using AdventureWorks2012 database. 1. Enable OLE Automation Procedures by running script below. Use AdventureWorks2012 Go EXEC sp_configure 'show advanced options' , 1; GO RECONFIGURE; GO sp_configure 'Ole Automation Procedures' , 1; GO RECONFIGURE; GO 2. Run the stored procedure script below. The script will return the LargePhoto of a specific product. USE AdventureWorks2012 GO IF OBJECT_ID( 'SP_AdventureWorks_Export_Blob' , 'P' ) IS NOT NULL DROP PROCEDURE S

Search Text In Files Using Utility Software Agent Ransack

Image
Hello, Just sharing a utility software that's something useful for searching text(s) from a number of files called Agent Ransack . This has been useful to me lately since I've been working on data formatting/cleanup projects that involves number of files. The tool is free and available for download from this site Agent Ransack . Sample Usage

Bootstrap Table Add Table Footer For Total Amount

Image
To add a footer row to the Bootstrap Table by Wenzhixin, set the data-show-footer attribute of that table to true. <table id= "tblInvoiceReport" data-show-footer= "true" > Next is to set the data-footer-formatter of the Amount column using a JavaScript function. <th data-field= "Amount" data-searchable= "true" data-class= "tdDetails" data-footer-formatter= "TotalFormatter" >Amount</th> And here's the JavaScript function to compute the total amount. function TotalFormatter (items) { var totalPrice = 0; items.forEach( function (item) { totalPrice = parseFloat(totalPrice) + parseFloat(item.Amount.replace( '$' , '' ).replace( ',' , '' )); }); return '$' + parseFloat(totalPrice).toLocaleString( undefined , { minimumFractionDigits: 2, maximumFractionDigits: 2 }); }; Output

How To Perform Bulk Update Using SqlBulkCopy, C#.NET And SQL Server

Image
Good afternoon! Before I go into details, this post is solely based on the solution provided in this link Bulk Update In C# . The purpose of this tutorial is to provide step by step approach on how bulk update can be achieved using SqlBulkCopy, C#.NET And SQL Server. First is to create a simple table in your database that holds some fictitious records. USE [testdatabase] GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[Person]( [ID] [int] NOT NULL , [Name] [varchar](50) NULL , [Address] [varchar](50) NULL ) ON [ PRIMARY ] GO Database table with temp records Next is to create a console app that will perform the bulk update of records. The key to solving performance issues in updating records is to use a temporary table approach. class Program { static void Main( string [] args) { var listPerson = new List<Person> { new Person() {Id = 1001, Name = "James A." , Address = "US" }, new Person(

Extend Primary Partition With Unallocated Disk Space In Windows 10 Using MiniTool Partition Wizard

Good evening team! While I was doing an inventory of my Dell laptop's disk space, I found out that it has an unallocated size of around 70 GB and my C:\ primary drive is running out of space. My goal is to extend the C:\ drive with the unallocated space so that I can install more softwares and similar applications. My journey started with the Disk Management to extend the primary drive. Unfortunately, the Extend Volume feature is disabled. I started looking for answers in forums and tried some recommended free partition software to solve my case. But still no luck. After several hours of research, I finally extended my primary drive using a partition tool called MiniTool Partition Wizard . The tutorial to add extend a primary partition using unallocated space is presented here How to Merge Unallocated Space in Windows 10 for a Large Partition . Look for Case 2: Add Unallocated Space to Partition Windows 10 for the specific steps. Cheers!

How To Remove Duplicate Items In A List<T> Using IEqualityComparer<T>

Image
Good evening. Here's a simple demo on how to remove duplicate items in a List object using IEqualityComparer given that the generic list's type is complex. First we setup a simple model Employee class with Age, Name and Address properties. class Employee { public int Age { get ; set ; } public string Name { get ; set ; } public string Address { get ; set ; } } Next is to create a comparer class that implements IEqualityComparer interface. class EmployeeComparer : IEqualityComparer<Employee> { public bool Equals(Employee emp1, Employee emp2) { if (Object.ReferenceEquals(emp1, emp2)) return true ; if (Object.ReferenceEquals(emp1, null ) || Object.ReferenceEquals(emp2, null )) return false ; return (emp1.Age == emp2.Age) && (emp1.Name == emp2.Name) && (emp1.Address == emp2.Address); } public int GetHashCode(Employee obj) {

Generate Insert Data Scripts Without Identity Column In SQL Server

I have been generating insert data scripts through SQL Server Management Studio on the fly. However if you don't want to include the ID which is an identity column,this feature is not defined in the IDE. The workaround for this is to insert the records without the ID column into a temporary table and generate insert data scripts using that temp table. Select PartNum, PartDescription, Model, Category, SaleQTY, Price Into tmptblParts From tblParts The query above will insert records from tblParts to temp table tmptblParts. The column ID is omitted. After you have executed that statement, then generate insert scripts using tmptblParts.

Cannot Delete Rows From A Temporal History Table In SQL Server

Given that you'll have to delete records from an SQL server history table, you might come across with the issue as mentioned in the title of the post. After doing some research and experiments, there are three steps to delete records from a temporal history table. a. First is to remove the main table's System Versioning option. ALTER TABLE [dbo].[tblParts] SET ( SYSTEM_VERSIONING = OFF ) b. Next is to delete the records of the temporal history table. Delete from dbo.tblPartsHistory WITH (TABLOCKX); c. Then Set again the system versioning and history table of the main table. ALTER TABLE [dbo].[tblParts] SET ( SYSTEM_VERSIONING = ON (HISTORY_TABLE = [dbo].[tblPartsHistory])) Solved.. :-)

Microsoft Access - The 'Microsoft.ACE.OLEDB.12.0' Provider Is Not Registered On The Local Machine

Image
Hello, I was working on a project that reads an MS Access database using C# using OLEDB Provider. I already have downloaded and installed the Microsoft Access Database Engine 2010 Redistributable (AccessDatabaseEngine_X64.exe) from Microsoft since my OS is Windows 10 64bit. Upon running the project, I encountered the error as mentioned in the title of this post. I've tried several solutions and it didn't work for me. The only fix that worked is to change the Platform target of the project to "Any CPU" and unchecked the Prefer 32-bit checkbox . Cheers! :)

Bootstrap Table Get Or Retrieve All Table Data On CheckAll Event

Good evening fellow developers! Here's are solutions on how to obtain the Bootstrap-Table by Wenzhixin data if the check all event is fired. The first one loops through the table rows and then looks for the element in the row that holds the data either in the element attribute or innerText and retrieves it using jQuery methods. $( '#AttachmentsTable' ).on( 'check-all.bs.table' , function (e, rows) { var allrows = $( "#AttachmentsTable tr" ); downloadAttachmentsArray.length = 0 ; downloadAttachmentsArray = []; $.each(allrows, function (i, item) { if (i > 0 ) { var aElem = $(item).find( 'a' ).attr( 'file' ); downloadAttachmentsArray.push({ Filename : aElem }); } }); }); The better solution uses the built-in getData method of the bootstrap table which returns an array. And then you may then loop through that array to get the data. $( '#AttachmentsTable' ).o

Read Files From Google Photos Using Google Photos API, REST And VB.NET

Image
This is the VB.NET version of the post Read Files From Google Photos Using Google Photos API, REST and C#.NET . In your VB.NET project, you need to reference the Google.Apis.Auth package via NuGet and attach the JSON file that contains the Google API credentials. The models used for converting a JSON response to .NET object are shown below. Public Class clsResponseRootObject Public Property mediaItems As List( Of MediaItem) Public Property nextPageToken As String End Class Public Class MediaItem Public Property id As String Public Property productUrl As String Public Property baseUrl As String Public Property mimeType As String Public Property mediaMetadata As MediaMetadata Public Property filename As String End Class Public Class MediaMetadata Public Property creationTime As DateTime Public Property width As String Public Property height As String Public Property photo As Phot

Read Files From Google Photos Using Google Photos API, REST And C#.NET

Image
Related Tutorials On Google Photos API Read Files From Google Photos Using Google Photos API, REST and VB.NET Upload Photos, Images Or Files To Google Photos Using Google Photos API, Rest and C#.NET I've been working on a project last year to read and download images from Google Photos using the recent Google Photos API and C# as the programming language. During research, there was an existing .NET API called Picasa Web Albums API but has been deprecated and the docs suggested to migrate applications to the recent one. The examples in the current documentation provided are PHP, Java and REST API in which the example is written in Node.js. Since the requirement is to write a scheduled task or windows service in C#.NET, I decided to refresh my skills on sending requests to REST services using WebClient or HTTPWebRequest classes. To access media items, read or even download files using Google Photos API, you need to enable the Google Photos Library API, create a Google Proj

Donate