Wednesday, September 9, 2015

Queue and Service Broker

Find db Users
SELECT * FROM sys.database_principals

Find Permission 
SELECT * FROM sys.database_permissions WHERE grantee_principal_id = 5

Create Queue and Service Broker
CREATE QUEUE PricesMessage;
CREATE SERVICE PricesNotifications
ON QUEUE PricesMessage
([http://schemas.microsoft.com/SQL/Notifications/PostQueryNotification]);

Grant Access For Queue (only run 1 time for all Queue 
GRANT RECEIVE ON QueryNotificationErrorsQueue TO dbadmeen;
GRANT SUBSCRIBE QUERY NOTIFICATIONS TO dbadmeen;
GRANT REFERENCES ON CONTRACT::[http://schemas.microsoft.com/SQL/Notifications/PostQueryNotification] TO dbadmeen;

Grant Access For Queue and ServiceBroker (Run for every queue and service) 
GRANT SEND ON SERVICE::[PricesNotifications] To dbadmeen;
GRANT RECEIVE ON [dbo].[PricesMessage] TO dbadmeen;
-- for user to see the services
GRANT VIEW DEFINITION ON SERVICE::[PricesNotifications] to dbadmeen;

****
Disable Queue & Enabale Queue
alter database dbName set disable_broker with rollback immediate;
alter database dbName set enable_broker with rollback immediate;

Get all the queue in that DB and numbers of message
SELECT sq.name, p.rows 

FROM sys.service_queues sq Join sys.internal_tables it ON sq.object_id = it.parent_id AND it.parent_minor_id = 0 AND it.internal_type = 201 Join sys.indexes as i on i.object_id = it.object_id and i.index_id = 1 Join sys.partitions as p on p.object_id = i.object_id and p.index_id = i.index_id WHERE sq.object_id = it.parent_id AND it.parent_minor_id = 0 AND it.internal_type = 201

See the queue

Select * From sys.dm_qn_subscriptions

Thursday, September 3, 2015

Rename Column

Use DBName
go


EXEC sp_rename '.dbo.Table.oldColumnName', 'NewColumnName', 'COLUMN'


-NewColumnName no need Tables or any . []

Tuesday, September 1, 2015

WF Errors

Error Message
Literal<Boolean>' is not of type 'Delay'. When loading this instance you must ensure that the activity with name 'Literal<Boolean>

Solve: It might be CorrelationID is null

Sunday, July 19, 2015

Q & A

A. 
It compiles your code into a .NET Assembly
B. 
It provides access to Microsoft’s library of code
C. 
It provides a common type system for your application
D. 
It is what your program runs inside of ... it protects the user from malicious code, and handles memory management and other runtime tasks
A. 
A block of code
B. 
A method
C. 
A function
D. 
A variable
A. 
A way to restrict access to your code
B. 
A named block of code that you can call / execute by calling its name
C. 
A means of organizing your code
A. 
A .NET Package
B. 
A .NET Component
C. 
A .NET
D. 
A .NET Assembly
A. 
An XML that contains project settings and the current state of the project
B. 
A file that contains all the C# code
C. 
A file that contains C# code containing project settings, files to include in the project, etc.
D. 
An XML file that contains information about all the project in a given solution

Monday, June 22, 2015

Find Gridview Row From List and check it.

foreach (var item in listPeople)
{
 var row = gvAddPeople.Rows.Cast<GridViewRow>()
.Where(x => ((HiddenField)x.Cells[0].Controls[3]).Value == item.PeopleID.ToString()).Single();

 ((CheckBox)row.Cells[0].Controls[1]).Checked = true;
}

Monday, June 1, 2015

Advanced LINQ

Get same attribute between 2 List

var listPerson = AlllistPerson.Where(x => listPhone
 .Any(y => x.PersonPhone.Contains(y.PhoneNmbers).ToList();

Remove from another List (duplicate)

var result = personList.Where(c => !transactionList.Exists(b => c.phone == b.phone)).ToList();

Remove from another List (duplicate) & Child List


List<long> phoneNumbers = sessionTelco.SelectMany
                            (x => x.PhoneList.Select(y => y.phone)).ToList();

coveragePrices = coveragePrices.Where(x => ! phoneNumbers.Contains(x. phone)).ToList();

Selecting First Item from every group

var grouped = personList.GroupBy(x => x.CountryName).Select(y => y.First()).ToList();

 var grouped = from x in personList
            group x by x.CountryName
            into y
            select y.First();


select many from child list.


List<long> routeClassIDList = _upc.SessionClientGroupList.SelectMany
         (x => x.ClientGroupCoverageList.Select(y => y.RouteClassID)).ToList();


filter all child list same with list


clientGroups = clientGroups.Where(x => !x.ClientGroupCoverageList.All(y => routeClassIDList.Contains(y.RouteClassID))).ToList();


ForEach Add if else


people.ForEach(x => { if (x.Balance.HasValue == false || x.Balance.Value == 0) x.Balance = null; });


INNER JOIN 
devicePerAccList = (from f in devicePerAccList
                    join s in Accounts on f.AccountId equals s.E2AccountId
                    select new DevicePerAcc
                    {
                        AccountId = f.AccountId,
                        AccCode = s.AccountCode,
                        NoOfDevice = f.NoOfDevice

                    }).ToList();

Select Many, Find Description, Filter Description = null, Order By 1A , 2B , 11A

preBookMealList = ssrReportList.SelectMany(a => a.SSRCodes.Select(b => new PreBookMeal
{
SSRCode = b,
SSRDescription = ssrMealList.Where(c => c.SSRCode == b).Select(d => d.Name).FirstOrDefault()
})
.Where(e => e.SSRDescription != null))
.OrderBy(f => int.Parse(f.SeatNo.Remove(f.SeatNo.Length - 1)))
.ToList();


Dictionary put Key to object ID

result = peopleList.Select(x => { x.Value.peopleID = x.Key; return x.Value; }).ToList();

Saturday, April 11, 2015

Bootstrap

HTML - CSS - JavaScript
Make sure to add jQuery file above the bootstrap file.

<div class="container-fluid">
Full width container

<div class="container">
Fixed width container

btn Modifier
–Default
–Primary
–Success
–Info
–Warning
–Danger