Monday, November 29, 2021
Wednesday, November 3, 2021
Issue MVC
Issue :
Unable to start program 'https://localhost:44391/'.
The debugger is not properly installed. Cannot debug the requested type of code. Run setup to install or repair the debugger.
Solution:
For me the fix was found in that thread, I disabled javascript debugging in the Tools -> Options -> Debugging -> General -> Enable Javascript debugging...
Wednesday, October 20, 2021
Open Port
Go to control panel
Windows firewall settings
Advance settings
Inbound rules
Add new rule
Select port
Add port and create
Create an Inbound Port Rule (Windows) - Windows security | Microsoft Docs
Monday, September 27, 2021
Access rights on folder ASP .Net
https://www.youtube.com/watch?v=qRW53_Xuhi8&ab_channel=BoobyBooby
RightClick on Folder
->Property
->Security
->Edit
->Add
->Advance
->Find Now
->Select IIS_IUSRS
-> OK
->OK
->Apply
->OK
Saturday, September 25, 2021
WKHtmlToPDF
What is it?
wkhtmltopdf
and wkhtmltoimage
are open source (LGPLv3) command line tools to render HTML into PDF and various image formats using the Qt WebKit rendering engine. These run entirely "headless" and do not require a display or display service.
There is also a C library, if you're into that kind of thing.
How do I use it?
- Download a precompiled binary or build from source
- Create your HTML document that you want to turn into a PDF (or image)
Run your HTML document through the tool.
For example, if I really like the treatment Google has done to their logo today and want to capture it forever as a PDF:wkhtmltopdf http://google.com google.pdf
Friday, September 24, 2021
File Zilla Setting for connect to ftp
i have made multiple changes in my filezilla, if you are not able to connect directly, use below step to make config changes in filezilla
In FileZilla, click on the File menu and choose Site Manager
Add the site or server in the site manager.
Add hostname
change the encryption to = only use plain FTP
Change logon type = Normal
Enter username/password.
Ok/Connect to continue
go to Edit -> Settings
Click on Connection -> FTP: Choose Active
Click on Connection -> FTP -> Active Mode: Select = Ask your operating system for the external IP address
Click on Connection -> FTP -> Passive Mode: Choose Fall Back to Active Mode
Press OK.
you should be able to connect now
make the above changes only if you are not able to connect
let me know if you were able to connect without making these changes or after making them
Tuesday, September 21, 2021
Rename Database
Select master first
USE master;
GO
ALTER DATABASE Logistics SET SINGLE_USER WITH ROLLBACK IMMEDIATE
GO
ALTER DATABASE Logistics MODIFY NAME = Logistics_Org ;
GO
ALTER DATABASE Logistics_Org SET MULTI_USER
GO
This configuration section cannot be used at this path. This happens when the section is locked at a parent level. Locking is either by default (overrideModeDefault="Deny"), or set explicitly by a location tag with overrideMode="Deny" or the legacy allowOverride="false".
1. Open "Turn windows features on or off" by: WinKey+ R => "optionalfeatures" => OK
- Enable those features under "Application Development Features"
Tested on Win 10 - But probably will work on other windows versions as well.
Thursday, September 9, 2021
Merge Two Memory Stream
var streamOne = new MemoryStream();
FillThisStreamUp(streamOne);
var streamTwo = new MemoryStream();
DoSomethingToThisStreamLol(streamTwo);
streamTwo.CopyTo(streamOne); // streamOne holds the contents of both
Find data in all tables
/* Reto Egeter, fullparam.wordpress.com */
DECLARE @SearchStrTableName nvarchar(255), @SearchStrColumnName nvarchar(255), @SearchStrColumnValue nvarchar(255), @SearchStrInXML bit, @FullRowResult bit, @FullRowResultRows int
SET @SearchStrColumnValue = '%notifications_dev%' /* use LIKE syntax */
SET @FullRowResult = 1
SET @FullRowResultRows = 3
SET @SearchStrTableName = NULL /* NULL for all tables, uses LIKE syntax */
SET @SearchStrColumnName = NULL /* NULL for all columns, uses LIKE syntax */
SET @SearchStrInXML = 0 /* Searching XML data may be slow */
IF OBJECT_ID('tempdb..#Results') IS NOT NULL DROP TABLE #Results
CREATE TABLE #Results (TableName nvarchar(128), ColumnName nvarchar(128), ColumnValue nvarchar(max),ColumnType nvarchar(20))
SET NOCOUNT ON
DECLARE @TableName nvarchar(256) = '',@ColumnName nvarchar(128),@ColumnType nvarchar(20), @QuotedSearchStrColumnValue nvarchar(110), @QuotedSearchStrColumnName nvarchar(110)
SET @QuotedSearchStrColumnValue = QUOTENAME(@SearchStrColumnValue,'''')
DECLARE @ColumnNameTable TABLE (COLUMN_NAME nvarchar(128),DATA_TYPE nvarchar(20))
WHILE @TableName IS NOT NULL
BEGIN
SET @TableName =
(
SELECT MIN(QUOTENAME(TABLE_SCHEMA) + '.' + QUOTENAME(TABLE_NAME))
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE = 'BASE TABLE'
AND TABLE_NAME LIKE COALESCE(@SearchStrTableName,TABLE_NAME)
AND QUOTENAME(TABLE_SCHEMA) + '.' + QUOTENAME(TABLE_NAME) > @TableName
AND OBJECTPROPERTY(OBJECT_ID(QUOTENAME(TABLE_SCHEMA) + '.' + QUOTENAME(TABLE_NAME)), 'IsMSShipped') = 0
)
IF @TableName IS NOT NULL
BEGIN
DECLARE @sql VARCHAR(MAX)
SET @sql = 'SELECT QUOTENAME(COLUMN_NAME),DATA_TYPE
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = PARSENAME(''' + @TableName + ''', 2)
AND TABLE_NAME = PARSENAME(''' + @TableName + ''', 1)
AND DATA_TYPE IN (' + CASE WHEN ISNUMERIC(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(@SearchStrColumnValue,'%',''),'_',''),'[',''),']',''),'-','')) = 1 THEN '''tinyint'',''int'',''smallint'',''bigint'',''numeric'',''decimal'',''smallmoney'',''money'',' ELSE '' END + '''char'',''varchar'',''nchar'',''nvarchar'',''timestamp'',''uniqueidentifier''' + CASE @SearchStrInXML WHEN 1 THEN ',''xml''' ELSE '' END + ')
AND COLUMN_NAME LIKE COALESCE(' + CASE WHEN @SearchStrColumnName IS NULL THEN 'NULL' ELSE '''' + @SearchStrColumnName + '''' END + ',COLUMN_NAME)'
INSERT INTO @ColumnNameTable
EXEC (@sql)
WHILE EXISTS (SELECT TOP 1 COLUMN_NAME FROM @ColumnNameTable)
BEGIN
PRINT @ColumnName
SELECT TOP 1 @ColumnName = COLUMN_NAME,@ColumnType = DATA_TYPE FROM @ColumnNameTable
SET @sql = 'SELECT ''' + @TableName + ''',''' + @ColumnName + ''',' + CASE @ColumnType WHEN 'xml' THEN 'LEFT(CAST(' + @ColumnName + ' AS nvarchar(MAX)), 4096),'''
WHEN 'timestamp' THEN 'master.dbo.fn_varbintohexstr('+ @ColumnName + '),'''
ELSE 'LEFT(' + @ColumnName + ', 4096),''' END + @ColumnType + '''
FROM ' + @TableName + ' (NOLOCK) ' +
' WHERE ' + CASE @ColumnType WHEN 'xml' THEN 'CAST(' + @ColumnName + ' AS nvarchar(MAX))'
WHEN 'timestamp' THEN 'master.dbo.fn_varbintohexstr('+ @ColumnName + ')'
ELSE @ColumnName END + ' LIKE ' + @QuotedSearchStrColumnValue
INSERT INTO #Results
EXEC(@sql)
IF @@ROWCOUNT > 0 IF @FullRowResult = 1
BEGIN
SET @sql = 'SELECT TOP ' + CAST(@FullRowResultRows AS VARCHAR(3)) + ' ''' + @TableName + ''' AS [TableFound],''' + @ColumnName + ''' AS [ColumnFound],''FullRow>'' AS [FullRow>],*' +
' FROM ' + @TableName + ' (NOLOCK) ' +
' WHERE ' + CASE @ColumnType WHEN 'xml' THEN 'CAST(' + @ColumnName + ' AS nvarchar(MAX))'
WHEN 'timestamp' THEN 'master.dbo.fn_varbintohexstr('+ @ColumnName + ')'
ELSE @ColumnName END + ' LIKE ' + @QuotedSearchStrColumnValue
EXEC(@sql)
END
DELETE FROM @ColumnNameTable WHERE COLUMN_NAME = @ColumnName
END
END
END
SET NOCOUNT OFF
SELECT TableName, ColumnName, ColumnValue, ColumnType, COUNT(*) AS Count FROM #Results
GROUP BY TableName, ColumnName, ColumnValue, ColumnType
Thursday, July 8, 2021
Task.Yield
You can use await Task.Yield();
in an asynchronous method to force the method to complete asynchronously. If there is a current synchronization context (SynchronizationContext object), this will post the remainder of the method's execution back to that context. However, the context will decide how to prioritize this work relative to other work that may be pending. The synchronization context that is present on a UI thread in most UI environments will often prioritize work posted to the context higher than input and rendering work. For this reason, do not rely on await Task.Yield();
to keep a UI responsive.
This can also be useful if you make an asynchronous method that requires some "long running" initialization, ie:
private async void button_Click(object sender, EventArgs e)
{
await Task.Yield(); // Make us async right away
var data = ExecuteFooOnUIThread(); // This will run on the UI thread at some point later
await UseDataAsync(data);
}
Without the Task.Yield()
call, the method will execute synchronously all the way up to the first call to await
.
Wednesday, June 30, 2021
EC-Counsil
1. How did you implemented OAuth?
2. How will you stop a application from opening in second tab?
Thursday, June 24, 2021
Database Anomalies
What is Database Anomaly?
Database anomaly is normally the flaw in databases which occurs because of poor planning and storing everything in a flat database. Generally this is removed by the process of normalization which is performed by splitting/joining of tables.
Prof_ID | Prof_Name | Dept. | Course Group |
39404 | Ashish | Marketing | Sec A |
39445 | Sonam | Product | Sec B |
43576 | Anu Priya | Finance | Sec C |
54325 | Anu Priya | Finance | Sec C |
99823 | Anushka | HR | Sec D |
14325 | Anushka | HR | Sec E |
There are three types of database anomalies:
a) Insertion anomaly: An insertion anomaly occurs when we are not able to insert certain attribute in the database without the presence of other attribute. For example suppose any professor is hired but not immediately assigned any course group or any department may not get his/her place in such type of flat database mentioned above, if null entries are not allowed in the database. So in the case mentioned above removing such type of problems requires splitting of the database which is done by normalization.
b) Update anomaly: This occurs in case of data redundancy and partial update. In other words a correct update of database needs other actions such as addition, deletion or both. For example in the above table the department assigned to Anushka is an error because it needs to be updated at two different place to maintain consistency.
c) Deletion Anomaly: Deletion anomaly occurs where deletion some data is deleted because of deletion of some other data. For example if Section B is to be deleted then un-necessarily Sonam’s detail has to be deleted. So normalization is generally done before deleting any record from a flat database.
Source : https://www.mbaskool.com/business-concepts/it-and-systems/12909-database-anomaly.html
Friday, June 18, 2021
ngAfterViewInit()
Angular ngAfterViewInit()
is the method of AfterViewInit
interface. ngAfterViewInit()
is a lifecycle hook that is called after Angular has fully initialized a component's views. ngAfterViewInit()
is used to handle any additional initialization tasks. Find the AfterViewInit
interface code from Angular doc.
interface AfterViewInit { ngAfterViewInit(): void }
ngAfterViewInit()
is used to access properties annotated with @ViewChild()
and @ViewChildren()
decorators.ngAfterViewInit() in Angular Lifecycle Hooks
ngAfterViewInit()
is executed after Angular initializes the component's views and child views. The child view is the view that a directive is in. ngAfterViewInit()
is executed only once after the first call of ngAfterContentChecked()
life cycle hook. After ngAfterViewInit()
lifecycle hook, the ngAfterViewChecked()
is called. ngAfterContentChecked()
responds after Angular checks the content projected into the directive/component and ngAfterViewChecked()
responds after Angular checks the component's views and child views.ngAfterViewInit
can be used with @ViewChild()
and @ViewChildren()
properties. ngAfterContentInit()
can be used with @ContentChild
and @ContentChildren
properties.Example
import { Directive, ViewContainerRef } from '@angular/core'; @Directive({ selector: '[cpMsg]' }) export class MessageDirective { constructor(public viewContainerRef: ViewContainerRef) { } }
import { Component, ViewChild, ViewChildren, AfterViewInit, TemplateRef, QueryList } from '@angular/core'; import { MessageDirective } from './message.directive'; @Component({ selector: 'app-message', template: ` <h3>@ViewChildren() and @ViewChild()</h3> <div cpMsg></div> <div cpMsg></div> <div cpMsg></div> <ng-template #msgTemp> Namaste! </ng-template> ` }) export class MessageComponent implements AfterViewInit { @ViewChildren(MessageDirective) private msgList: QueryList<MessageDirective>; @ViewChild('msgTemp') private msgTempRef: TemplateRef<any>; ngAfterViewInit() { console.log("this.msgList.length: " + this.msgList.length); this.msgList.forEach(messageDirective => messageDirective.viewContainerRef.createEmbeddedView(this.msgTempRef)); } }
ngAfterViewInit()
responds when the component's view and its child view is initialized, so here inside this method we are reading the msgTemp
template data and embedding it into the cpMsg
directive.When to use Include() with Entity Framework?
When to use Include with Entity Framework and is it related to lazy loading?
Before jumping into the answer of when to use Include, let's have a look at the following simple example which contains three entities.
public class Customer { public int CustomerID { get; set; } public string Name { get; set; } public virtual List<Invoice> Invoices { get; set; } } public class Invoice { public int InvoiceID { get; set; } public DateTime Date { get; set; } public int CustomerID { get; set; } public virtual Customer Customer { get; set; } public virtual ICollection<Item> Items { get; set; } } public class Item { public int ItemID { get; set; } public string Name { get; set; } public int InvoiceID { get; set; } public virtual Invoice Invoice { get; set; } }
- Lazy loading is the process whereby an entity or collection of entities is automatically loaded from the database.
- Lazy loading is enabled by default in Entity Framework, and we can mark specific navigation properties or even whole entities as lazy by making them virtual.
Now let's retrieve all the customers from a database and also iterate over their invoices as well and then print the invoice date.
using (var context = new MyContext()) { var list = context.Customers.ToList(); foreach (var customer in list) { Console.WriteLine("Customer Name: {0}", customer.Name); foreach (var customerInvoice in customer.Invoices) { Console.WriteLine("\tInvoice Date: {0}", customerInvoice.Date); } } }
If you look at the generated SQL, then you will see that one SQL query is executed for retrieving customers and then for each customer, another query is executed for retrieving the Invoices related to that customer. So, it means, if you have 1000 customers in your database then EF will execute 1000 queries for retrieving invoices for that 1000 customers.
EF generates the following query for retrieving customers.
SELECT [Extent1].[Id] AS [Id], [Extent1].[Name] AS [Name] FROM [dbo].[Customers] AS [Extent1]
And the following query is generated for retrieving invoices of a specific customer.
1SELECT
2 [Extent1].[Id] AS [Id],
3 [Extent1].[Date] AS [Date],
4 [Extent1].[CustomerId] AS [CustomerId]
5 FROM [dbo].[Invoices] AS [Extent1]
6 WHERE [Extent1].[CustomerId] = @EntityKeyValue1
- Lazy loading is a great mechanism but only if you know when and how to use it.
- But look at our example again. Now if you look at this example, then you will see the select N+1 problem.
- The problem is happening because the Lazy loading is enabled by default and when we are executing a single query and then N following queries (N is the number of parent entities) to query for something.
The best way to avoid the select N+1 problem in Entity Framework is to use the Include method. It will create one query with needed data using SQL JOIN clause which is more efficient as compared to the previous one.
Let's update our query by using the Include method.
using (var context = new MyContext()) { var list = context.Customers .Include(c => c.Invoices) .ToList(); foreach (var customer in list) { Console.WriteLine("Customer Name: {0}", customer.Name); foreach (var customerInvoice in customer.Invoices) { Console.WriteLine("\tInvoice Date: {0}", customerInvoice.Date); } } }
In the above example, we are telling EF explicitly that besides Customers we also need their Invoices. The following is the SQL generated query:
1SELECT
2 [Project1].[Id] AS [Id],
3 [Project1].[Name] AS [Name],
4 [Project1].[C1] AS [C1],
5 [Project1].[Id1] AS [Id1],
6 [Project1].[Date] AS [Date],
7 [Project1].[CustomerId] AS [CustomerId]
8 FROM ( SELECT
9 [Extent1].[Id] AS [Id],
10 [Extent1].[Name] AS [Name],
11 [Extent2].[Id] AS [Id1],
12 [Extent2].[Date] AS [Date],
13 [Extent2].[CustomerId] AS [CustomerId],
14 CASE WHEN ([Extent2].[Id] IS NULL) THEN CAST(NULL AS int) ELSE 1 END AS [C1]
15 FROM [dbo].[Customers] AS [Extent1]
16 LEFT OUTER JOIN [dbo].[Invoices] AS [Extent2] ON [Extent1].[Id] = [Extent2].[CustomerId]
17 ) AS [Project1]
18 ORDER BY [Project1].[Id] ASC, [Project1].[C1] ASC
As you can see that Entity Framework has used LEFT OUTER JOIN
clause to get all needed data. Another important point is that using Include method in the context which supports lazy loading can prevent the n+1 problem.