Monday, December 21, 2015

Error accessing the system registry

If you get above error, make sure you open your Visual Studio 6.0 with "Run as Administrator" option.

You can also set this option permanently by going to the file location of Visual Basic 6.0 shortcut.
On the file, right click and go to Properties.
In Properties, select Compatibility tab.
In this tab, you will see "Run this program as an administrator" check box.
Check it and click OK.

This should do the trick permanently and now you don't need to open project by Run as Administrator option anymore.

HTH.

Tuesday, December 15, 2015

Parse Date in VB6

VB6 is not smart to understand some usual date formats that we use daily.
So for example, if you were to put yyymmdd in date type, VB6 will give Type mismatch error.


You would need to parse it to store in date type field as below:


Dim strDate as string
Dim dBusinessDate as date


strDate = "20151211"
dBusinessDate = Mid(strDate, 5, 2) & "/" & Right(strDate, 2) & "/" & Left(strDate, 4)

For more info: See Dates on MS page




HTH

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

Friday, June 19, 2015

Adding reference in SSIS package


Hello,
The following blog will help users to deploy referenced dll in SSIS package while deploying to Integration Services.

Environment:
  1. SQL Server 2008 
  2. Visual Studio 2008 (Business Intelligence Projects)


To add reference of any dll in SSIS package, you go to project properties and browse to dll to add as a reference. It should also be in your local machine GAC else it wont work.
SSIS project doesn’t have bin folder so it always look for assemblies from GAC.

Now to run on sql server (using Integration Services), the same dll must be added to GAC on SQL Server machine.


Note: For assembly to be added in GAC, it  must have strong name.

HTH.

Monday, May 25, 2015

The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required.

Hello,
While I was trying to send an email from a website using gmail account, I didn't have any issues testing on my local machine but getting to work from production server was a pain.
I was keep getting error message:

"The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required."

3 things will fix it:
  1. Go to security settings at the following link https://www.google.com/settings/security/lesssecureapps and enable less secure apps. This will enable google to login from all apps.
  2. Enable other ip/timezone for your google account by clicking on following link and click continue to give access: https://g.co/allowaccess
  3. Go to account settings 
    • Under Recent Activity section, click on "Notifications and Alerts" 
    • Now there you will see "Unusual Activity". 
    • Select your related event and approve it by clicking "Yes, That was me!".   This way google will add this clear this activity from suspicious list of activities.
HTH

Tuesday, May 19, 2015

Why my website is running in 32 bit mode in Visual Studio?

I was working on a website in Visual Studio 2013 in 64 bit machine. The properties of solution/project was set to run as Any CPU which means to run the app as 64 bit when 64 bit processor found else 32 bit.

In my 64 bit machine, the website was being starting as 32 bit and the reason was that the process hosting the website was "IISExpress" and it was being run in 32 bit mode.

Again, the Any CPU flag also follow the caller of the app. 
If the caller of app is running in 32 bit, the application would run in same as well.

Anyways, to change the IISExpress to run as 64 bit, check the box under :

Tools | Options | Projects and Solutions | Web Projects | Use the 64 bit version of IIS Express

HTH


Monday, May 4, 2015

SQL Server Stored Procedure Alter / View / Execute Permissions

There are different ways to grant user permission to alter, view or execute stored procedures.
The easiest approach I found was to create a "Database Role".
Name anything you like. I liked "db_executor" role.
Now give this role permissions and then add users to this role.

So..

/* Create a new role for stored procedure permissions */
CrEATE ROLE db_executor

/* Grant stored procedure Alter/View/Execute rights to the role */
GRANT ALTER, VIEW DEFINITION, EXECUTE TO [db_executor]

/* Add a user to the db_executor role */
EXEC sp_addrolemember 'db_executor', [domain\userid]  -- No single quotes around user.

Friday, April 17, 2015

Thursday, January 29, 2015

Brother Printer Replace Toner Message

If you ever get in a state where your printer hold you as hostage because of low toner message, follow following steps to reset the toner flag:

1. First find the IP address of your printer.
    To find IP address,

  •    -> Go to control panel -> Devices and Printers
  •    -> On you printer, right Click on printer and click on Printer Properties
  •    -> Select Ports tab
  •    -> Click Configure Port
  •    -> In the window, you will see Printer Name
  •    -> Go to command prompt, type ping <printerName>
  •    -> Ping command will display IP address.
2. Open your browser window. Type in the IP address and hit Enter.
3. This will default page of printer. 
4. On the Right side, Click on "Replace Toner" link. This will take you to replace toner page.
5. Click "Continue" and hit Submit.
6. Done.


HTH.

Saturday, January 10, 2015

How to find tables in FileGroup in SQL Server?

To find all the objects / tables / Indexes  that exist in a Filegroup, use following query:

SELECT
      f.[name] AS [FileGroupName]
    , OBJECT_SCHEMA_NAME(p.object_id) AS [Schema]
    , OBJECT_NAME(p.object_id) AS [Table]
    , i.name AS [Index]
    , p.rows AS [Row Count]
    , i.type_desc AS [Index Type]
FROM sys.indexes i
INNER JOIN sys.filegroups f
ON i.data_space_id = f.data_space_id
INNER JOIN sys.all_objects o
ON i.object_id = o.object_id
INNER JOIN sys.partitions p
ON i.object_id = p.object_id
AND p.index_id = i.index_id
WHERE o.type = 'U' -- User Created Tables
-- and f.name = '<filter for interested filegroup using name>'
order by p.rows