Emulator For Turbo C++ for 32/64 bit OS

Hi,

Below is the link for the emulated turbo C++ application which is successfully running on 32/64 bit OS (Win Vista/7/2k8).

Emulated Turbo C++

Hope it helps.

Thanks,

/Ashlesh

 

Error message 1785 occurs when you create a FOREIGN KEY constraint that may cause multiple cascade paths

While getting the above error either remove the cascade action from the relationship or create a delete/update trigger on the particular table as below sample:

Consider two tables (Orders and OrderDetails)

DELETE Trigger:

CREATE TRIGGER trg_d_orders_on_delete_cascade ON Orders FOR DELETE
AS

DELETE FROM OrderDetails
FROM
    OrderDetails AS OD
  JOIN
    deleted      AS D ON OD.orderid = D.orderid
  GO

Process flow for DELETE Trigger:

Testing the trg_d_orders_on_delete_cascade trigger
DELETE FROM Orders
WHERE orderid = 10002

Take a look at Figure 5, which shows what’s happening inside the trigger.

Aa902684.sql_refintegrity05(en-us,SQL.80).gif

Figure 5. Inside the CASCADE DELETE trigger

The DELETE operation in the preceding script starts the following activity:

  1. The DELETE operation is written to the transaction log.
  2. Order 10002 is deleted from the Orders table.
  3. The DELETE trigger is fired. While inside the trigger, order 10002 does not exist in the Orders table. The deletedtable, which you can think of as a view on the deleted row in the transaction log, contains the row for order 10002.
  4. The DELETE trigger deletes all related rows from the OrderDetails table by performing a join between thedeleted table and the OrderDetails table. The join is used here to filter only the related rows in the OrderDetailstable.
UPDATE Trigger:
CREATE TRIGGER trg_u_orders_on_update_cascade ON Orders FOR UPDATE
AS

DECLARE @numrows int
SET @numrows = @@rowcount
IF UPDATE(orderid)
  IF @numrows = 1
    UPDATE OrderDetails
      SET orderid = (SELECT orderid FROM inserted)
    FROM
        OrderDetails AS OD
      JOIN
        deleted      AS D ON OD.orderid = D.orderid
  ELSE IF @numrows > 1
  BEGIN
    RAISERROR('Updates to more than one row in Orders are not allowed.  
              TRANSACTION rolled back.', 10, 1)
    ROLLBACK TRANSACTION
  END
  GO

Process flow for DELETE Trigger:

Testing the trg_u_orders_on_update_cascade trigger
  UPDATE Orders
  SET orderid = 10004
  WHERE orderid = 10002

Take a look at Figure 6, which shows what’s happening inside the trigger. You join the deleted table with theOrderDetails table to filter only the related order details, and then update their orderid column to the new value, which is fetched from the inserted table by using a subquery. You can issue such a subquery because you know that there is one and only one row in the inserted table; otherwise, the subquery would have returned more than one value and the update would have failed. Thus you get the required result, as shown in the following tables.

Aa902684.sql_refintegrity06(en-us,SQL.80).gif


Please visit this link for more details.
Hope it helps.
/Ashlesh

Search for specific value in Registry keys using Log Parser

Hi,I found a great help of microsoft from one of the blog as below. It helps us to find a registry key from a particular value.

Microsoft has a great (but not well known) tool for this – called LogParser

It uses a SQL engine to query all kind of text based data like the Registry, the Filesystem, the eventlog, AD etc… To be usable from C#, you need to build an Interop Assembly from the Logparser.dll COM server using following (adjust LogParser.dll path) command.

tlbimp "C:\Program Files\Log Parser 2.2\LogParser.dll"
/out:Interop.MSUtil.dll

Following is a small sample, that illustrates how to query for the Value ‘VisualStudio’ in the \HKLM\SOFTWARE\Microsoft tree.

using System;
using System.Runtime.InteropServices;
using LogQuery = Interop.MSUtil.LogQueryClass;
using RegistryInputFormat = Interop.MSUtil.COMRegistryInputContextClass;
using RegRecordSet = Interop.MSUtil.ILogRecordset;

class Program
{
public static void Main()
{
RegRecordSet rs = null;
try
{
LogQuery qry = new LogQuery();
RegistryInputFormat registryFormat = new RegistryInputFormat();
string query = @"SELECT Path from \HKLM\SOFTWARE\Microsoft where
Value='VisualStudio'";
rs = qry.Execute(query, registryFormat);
for(; !rs.atEnd(); rs.moveNext())
Console.WriteLine(rs.getRecord().toNativeString(","));
}
finally
{
rs.close();
}
}
}

Debugging a custom Installer class

Hi,

I found a useful post to debug the custom installer class in .net on joshrobinson post.

To debug the custom installer class, you should follow below steps:
How you do it is this :
1. Place a breakpoint in your installer class.
2. Just before the break point add this line
System.Diagnostics.Debugger.Break();
3. When you run the installer… i.e. when you try to install, the installer will give a message with an option to debug. Click the debug button and select your already open Visual Studio and select Yes.

Thanks.

Make installer program to uninstall the application using Visual Studio setup program

Hi,

Normally setup project doesn’t support that function and also Microsoft recommend users to uninstall applications via Control Panel. But you can use the following way to make an uninstall program along with your application.

1). Provide now you have an application and a setup project, you can create another application called UninstallApp . That application can be a simple console application.

2). To uninstall an application, you need to run “MsiExec.exe /I {productcode} ” in the command line. That can bring out an uninstall wizard to move on to the next.

3). For example now you have an application whose product code is “09411687-F56E-4480-906A-F0186A9FF6CE”, so the UninstallApp can be coded like this.

namespace UninstallAPP
{
class Program
{
static void Main(string[] args)
{
Process uninstallProcess = new Process();
uninstallProcess.StartInfo.FileName = “MsiExec.exe”;
uninstallProcess.StartInfo.Arguments = “/I{09411687-56E-4480-906A-F0186A9FF6CE}”;
uninstallProcess.StartInfo.UseShellExecute = false;
uninstallProcess.Start();
}
}
}

4). Now you can add UninstallApp console application to the setup project and create a shortcut for it. You can name the shortcut as “Uninstall”.

You can also find more info on VS Setup Discussion.

Regards,
/Ashlesh

File system tree view

Hi,

Below  link contains the code which loads the treeview control for file system. Worth to review.

http://www.codeproject.com/KB/tree/FileSystemTreeView.aspx

Thanks.

/Ashlesh

SQL SERVER – FIX : ERROR : (provider: Named Pipes Provider, error: 40 – Could not open a connection to SQL Server) (Microsoft SQL Server, Error: )

Hi,

Useful link to resolve this problem. Mentioned all possible techniques to fix it.

SQL SERVER – FIX : ERROR : (provider: Named Pipes Provider, error: 40 – Could not open a connection to SQL Server) (Microsoft SQL Server, Error: )

Good materials for VB6.0 and VB.NET

http://www.functionx.com/vb/index.htm

Using Measurement Studio ActiveX Controls in Visual Studio .NET

AA very good link which shows the activeX event and handlers.

http://zone.ni.com/devzone/cda/tut/p/id/4587

Whats the difference between Control.Invalidate, Control.Update and Control.Refresh?

Before discussing each one of the above functions, let’s look at how winforms controls paint.

Windows controls paint is response to WM_PAINT messages. This message is sent when UpdateWindow or RedrawWindow is called, or by the DispatchMessage function when the application gets a WM_PAINT through the message queue. On getting the WM_PAINT message, the control paints its background and then the foreground if necessary. Double-buffering and transparency is honored while painting and then the OnPaint event is fired to give the user a chance to perform his custom painting.

With this background, let’s look at the above mentioned three functions in more detail,

Control.Invalidate( ) / Control.Invalidate(bool) / Control.Invalidate(Rectangle) / Control.Invalidate(Rectangle, bool) / Control.Invalidate(Region) / Control.Invalidate(Region, bool)

The bool parameter denotes whether the user wants to invalidate the child controls of the control on which he is calling Invalidate. The Rectangle parameter are the bounds to invalidate and the region parameter is the region to invalidate. All the overloads essentially end up calling one of the RedrawWindow, InvaliateRect or InvalidateRgn functions. If RedrawWindow is called then this may result in a WM_PAINT message being posted to the application message queue (to invalidate the child controls).

The important thing to note here is that these functions only “invalidate” or “dirty” the client area by adding it to the current update region of the window of the control. This invalidated region, along with all other areas in the update region, is marked for painting when the next WM_PAINT message is received. As a result you may not see your control refreshing (and showing the invalidation) immediately (or synchronously).

Control.Update()

Update function calls the UpdateWindow function which updates the client area of the control by sending WM_PAINT message to the window (of the control) if the window’s update region is not empty. This function sends a WM_PAINT directly to WNDPROC() bypassing the application message queue.

Thus, if the window update region is previously “invalidated” then calling “update” would immediately “update” (and cause repaint) the invalidation.

Control.Refresh()

By now, you might have guessed what Refresh( ) would be doing. Yes, it calls Invalidate(true) to invalidate the control and its children and then calls Update( ) to force paint the control so that the invalidation is synchronous.