Friday, November 13, 2015

Windows 10 Search with - in file name

If you have "-" in the beginning of word that you want to use to search file, Windows 10 wont be able to search.
To use search, you would replace "-" with "*".



Example:
If file name is: Hello-saqib-7526.txt, and you want to search files with "saqib", you would use *saqib or *7526.


HTH

Wednesday, November 4, 2015

Cast to Int16 - Type Conversion

In VB.net, if you need to convert number/string (assuming its number) to Int16, there isn't any function as Cint16 as there is for CInt.

Instead you would write :
Convert.Int16(value)
or
CType(value, Int16)

Thursday, October 29, 2015

Share folder Permissions - Just basic stuff

Once the folder is shared on network, all previous permissions need to be revised on the folder. The admin of machine where the folder is shared from doesn't even have permission once the folder is shared.

So 2 things need to be set under Sharing and Security tabs of folder.
Right click on folder and you see both these folders:

Sharing tab: Click on Share button. A window will open. Add the user and then on right column give necessary permissions to this newly added user.

Security tab: Click on Edit button. A window will open. Add the user and then on bottom pane, give necessary permissions to this newly added user.

There are many other things you can control hierarchical wise which you welcome to search on your own.


HTH.

Wednesday, October 28, 2015

How to get distinct records from array?

Using linq, it's pretty easy to get distinct records from array.
Lets say you have file filled with record and you read the file into array.
Now on this array, you can use lambda/linq expression to filter the list.
The code will keep the first record it found and throws all duplicates after it found the first one.

For my work, it was matter because I need to process in the order
they receive.


' Read complete file.
Dim lines() As String = File.ReadAllLines("C\dummyrecord.txt")


' group array items and get the first record.
Dim distinctList = lines.GroupBy(Function(x) x.ToString).Select(Function(grp) grp.First).ToArray


That's it!!


This line will return an String Array as well. Depending on your choice, you can also get
different data structures instead of array.


Linq Explanation:

2 functions are used: GroupBy and Select. Both take function as an argument which let you reference the items of object (array/list).
GroupBy will take function as argument using which you can reference elements of array/object.
Then you using Select method, you reference the grouped items and get the first record of many duplicate records.


HTH!

Tuesday, September 29, 2015

How to troubleshoot error 20598 - The row was not found at the Subscriber when applying the replicated command

Hi,

This is the error message you will get if the data is modified directly in Subscriber.
There are few steps, if you follow will help you to know the table with some data (basically just the PK) that the command is trying to apply towards subscriber.

Connect to your distributor server:

use distribution
select * from MSrepl_errors order by time desc

This command will give you all the errors occurred in replication.



Extract the command from the value in xact_seqno column above using the following store procedure:


exec dbo.sp_browsereplcmds '0x001927CF000678CD001400000000','0x001927CF000678CD001400000000'


The command column will show the command replication engine is trying to execute with each sp defined with action name on the table and the key value.

Solution:
There are 2 ways you can fix this problem:
  1. Insert the missing data in Subscriber. You might have to do this step more than once. Once replication engine can find that missing row, it will apply the action. You would only need to fill in Primary key columns.
  2. Make a change in the Distribution Agent to skip this error and continue with the replication. Distribution agent accepts the skiperrors parameter which will be 20598 in this case.
HTH

Wednesday, September 9, 2015

Delete duplicate Rows from datatable

Hi,

To delete duplicate rows from datatable in vb.net, first we need to sort table on the keys that will be used to delete rows.

Sort asc if the row to be deleted has highest value.
Sort desc if the row to be deleted has least value of duplicate.

In this example, I want to keep the highest filecount in any duplicated time. So I will sort desc.
In the function below, I pass the datatable that has duplicate set.
I have also cloned of Filedt to store duplicated rows.
Then based on sortString, I will apply select on datatable and return array of rows.
Now when I start looping the rows, I will save the prevRow and then match it with next row. If next row is same, I will save it in prevRow, import in cloned datatable and then delete it.

Private Function RemoveDupsdt(ByRef Filedt As DataTable) As DataTable

        Dim cloneDT As DataTable = Filedt.Clone
        Dim sortString As String = "ProcessingTime asc, FileCount desc"
        Dim prevRow As String = ""
        Dim rowlist As DataRow() = Filedt.Select("", sortString)
        Dim dcIssue As New DataColumn("Issue", GetType(String))
        dcIssue.DefaultValue = "Duplicate"

        For Each dr As DataRow In rowlist
            If prevRow = dr.Item("ProcessingTime")  Then
                prevRow = dr.Item("ProcessingTime")
                cloneDT.ImportRow(dr)
                dr.Delete()
            Else
                prevRow = dr.Item("ProcessingTime")
            End If
        Next

        cloneDT.Columns.Add(dcIssue)
        RemoveDupsdt = cloneDT

    End Function

Friday, September 4, 2015