Sunday, 4 November 2012

New Debugger Behavior in Visual Studio 2012

I have a .NET 3.5 library project to debug. To do it I launch it through an external exe compiled with Delphi in native code.
This works great in visual studio 2010 and earlier, I never had any issue of any type.
This doesn't works anymore in visual studio 2012: the debugger doesn't stops, breakpoints are simply ignored.

The key point is that the selection of the target framework under "Application" tab to be .Net 3.5 only affects building the class library project under the current solution. This setting, at least in VS 20102, does not influence what debugger engine type (i.e., .net 4.0? 3.5?) uses to attach to the external program. As a result VS does not know what .Net version the class library being loaded by your external app, and by default assumes .Net 4.0. Unfortunately, .Net 4.0 debug engine does not work on .NET code v3.5 or prior.

Solution #1: Use Debug -> Attach to Process -> Change the debugger type by hitting the "Select..." in the dialog and choosing "Managed (v3.5, v3.0, v2.0) code" -> Choose external exe -> Attach. Now, you are explicitly telling VS you want to use the debug engine for .Net 3.5 or prior.

Solution #2: Make your external app the "Start up project". In Visual Studio, File -> Open -> Project, and select your Delphi app. You have just created a new solution with the delphi binaries as the startup project. If you go to the project properties, you can change the "Debugger Type" from 'Auto' to 'Managed (v3.5, v3.0, v2.0)'. By doing this, you have told Visual Studio explicitly you want to use the debug engine for .Net 3.5 or prior. Now, the breakpoints in your class library code will hit, as long as you maintain having the external delphi app as your startup project and setting the Debugger Type explicitly to use .Net 3.5 or prior.

This is the complete discussion with M$ guys at Microsoft Connect:

Wednesday, 26 January 2011

Reporting Service Permissions on Windows 7

I installed RS on a brand new installation on windows 7 x64 with SqlServer 2008 R2, The user I was logged on had full administrative privileges, UAC was turned on as normal.

As soon I tried to access the Reporting Services Site I got the following error: The permissions granted to user 'DOMAINNAME\USERNAME' are insufficient for performing this operation


After struggling against services permissions and many other more stuff I did the following

-          Go into user management and enable the built-in administrator account

-          Log on as built-in administrator

-          Open the Report Manager and setup proper roles for my user

-          Logon with my user account, now all works…

-          You can now go back to user management and disable the built-in administrator account


Thursday, 20 January 2011

Windows Backup Issue

Windows Backup failed while trying to read from the shadow copy on one of the volumes being backed up. Please check in the event logs for any relevant errors.

Error code: 0x81000037

My system was a Windows 7 x64 Ultimate, and I was backing up to an internal HD, so nothing could be more standard

After some searching I’ve found that the problem was generated indirectly from windows media player: after configuring music library it added the root music location to system libraries. I manually removed the item from the sys libraries and … wow ! now works !

The problem (maybe) was that the link in the sys libraries was pointing to a folder that is a mount point for another internal HD with all my music stuffs.

Saturday, 27 November 2010


A lot of spam in this period... so I've changed setting to allow comments for registered users only.

Monday, 1 February 2010

Using C# assembly from Delphi Win32

A hands-on lab on how to call a C# class from within delphi win32 code


1. First declare a C# interface as follows




    public interface IMyClass


        void DoSomething();



2. Write a class that implements the interface

    class MyClass : MarshalByRefObject, IMyClass


        public void DoSomething()






3. Make sure to set the assembly COM-Visible: Project options -> Application Tab -> Check “Make assembly COM visible”



4. Declare the same Interface also in delphi:


IMyClass = interface ['{1F3E8CE4-A8BF-47B3-A31E-A07BB3ECD192}']

  procedure DoSomething; safecall;



5. Create and use the class with the following code:

function ClrCreateManagedInstance(pTypeName: PWideChar; const riid: TIID; out ppObject): HRESULT; stdcall; external 'mscoree.dll';


procedure DoSomething;

var mc: IMyClass;

    hr: HRESULT;

    NetClassName: WideString;


    //Partial assembly name works but full assembly name is preffered.

    NetClassName := 'MyAssembly.MyClass, MyAssembly'; // 'Full type name, dllName'

    hr := ClrCreateManagedInstance(PWideChar(NetClassName), IMyClass, mc);






That’s all.

For more detailed info please visit the following links



Thursday, 17 December 2009

Welcome to

From the site home page: “The programmer's file and data format resource. This site contains information on hundreds of different file types, data types, hardware interface details and all sorts of other useful programming information; algorithms, source code, specifications, etc.

It is a quite useful site with plenty of information, really worth a bookmark on your favorites:


Monday, 16 November 2009

Default Debugger

By default, Microsoft Windows uses Dr. Watson debugger as the default debugger. This can be altered in the Windows registry manually by a user or by the installation of software such as Visual Studio or Delphi.

I think that having Visual Studio popped up each time an application crashes can be very annoying especially if you are performing some test but you don't need to debug that application.

The solution is to ensure that Dr. Watson is the default debugger of the Windows operating system.

To do this find the following registry key:


and set it to the following string "drwtsn32.exe -p %ld -e %ld"

Wednesday, 29 April 2009

Problems enabling service broker

If you restore a database with service broker enabled on the same sql server instance, it may happen that broker doesn't enables and when try to manually enable it you may get back the following error message:


The Service Broker in database "??????" cannot be enabled because there is already an enabled Service Broker with the same ID


This statement fixed the situation:


alter database ?????? set NEW_BROKER

Tuesday, 11 November 2008

Print What You Like

Ever print a web page only to find your printout is full of ads, empty space and other junk you don't want? PrintWhatYouLike is a free web page editor that gives you control of how web pages look when printed.


How it works ? quite simple

1.       Go to the page you want to print

2.       Copy and paste in the address bar the script below and hit return




Go to for more info.


A great resource on SQL and XML

This is really a great site. It has a lot of tutorials and code that works fine !

A simple search that uses google and really find what’s useful.

It could not be done better.

Really many thanks to Jacob Sebastian.


Thursday, 16 October 2008

How to cleanup SQL Server Service Broker

If you need to cleanup or reset Service Broker, you may find useful this short script that shuts down all open conversations and cleans up the Service Broker queue.


declare @u uniqueidentifier

select top 1 @u=conversation_handle from sys.conversation_endpoints

while @u is not null begin


  set @u = null

  select top 1 @u=conversation_handle from sys.conversation_endpoints



Hope that helps.

Monday, 13 October 2008

Reset SQL Schema during your coding sessions

I think that anyone that writes SQL code has coded like the following:










This is quite common for me during the testing phase, since I find myself comfortable in writing a single script that drops & recreates all objects under development… but it is also quite frustrating to copy & paste always the same code only to change the object name.

So I’ve decided to look a way to avoid repeating the same code again and again… the solution I’ve find is to query INFORMATION_SCHEMA to list object I need and then to build dynamic queries to drop those objects.


Here follows a short script that drops a certain number of  tables all prefixed by 'wf_%' string, the script drops the constraints first and then the tables:


declare @spname sysname

declare spCur cursor

    read_only for

    select 'ALTER TABLE ' + foreign_table + ' DROP CONSTRAINT [' + fk_name + ']'

      from foreign_keys

      where ((primary_table like 'wf_%') or (foreign_table like 'wf_%'))


    select  case when table_type = 'view' then 'DROP VIEW ' + table_schema + '.[' + table_name + ']'

                 else 'DROP TABLE ' + table_schema + '.[' + table_name + ']'



        where (table_name like 'wf_%') and table_catalog = db_name()

open spcur

FETCH NEXT FROM spcur INTO @spname

WHILE (@@fetch_status = 0) BEGIN

    exec (@spname)

       FETCH NEXT FROM spcur INTO @spname


CLOSE spcur




You can also drop any other type of object by referring the right schema tables, for example this is how to drop stored procedures and functions


    select 'DROP ' + ROUTINE_TYPE + ' ' + routine_schema + '.[' + routine_name + ']'

        from information_schema.routines

        where (routine_name like 'wf_%') and routine_catalog = db_name()


Just to be complete… here the script that creates the foreign_keys view


CREATE  view dbo.foreign_keys as

   select cast(  as varchar(255)) as fk_name

    , r.keycnt

    , cast( as  varchar(255)) as foreign_table

    , cast( as varchar(255))  as foreign_col1

    , cast( as varchar(255))  as foreign_col2

    , cast( as varchar(255))  as primary_table

    , cast( as varchar(255))  as primary_col1

    , cast( as varchar(255))  as primary_col2

    from sysobjects f

    inner join sysobjects ft on  f.parent_obj =

    inner join sysreferences r on =  r.constid

    inner join sysobjects pt on r.rkeyid =

    inner  join syscolumns p1 on r.rkeyid = and r.rkey1 = p1.colid

    inner  join syscolumns f1 on r.fkeyid = and r.fkey1 = f1.colid

    left join  syscolumns p2 on r.rkeyid = and r.rkey2 = p1.colid

    left join  syscolumns f2 on r.fkeyid = and r.fkey2 = f1.colid

    where f.type =  'F'



Hope that helps




Saturday, 4 October 2008

CLR Via C# Second Edition (by Jeffrey Richter)

This is absolutely the best book I've read on programming CLR. It is focused on CLR features and capabilities and C# is only a way to access them, so you will find a lot of real-world tips&tricks that will route you on the right way, so avoiding a lot of common errors. The best chapter, IMO, is the one that explain how multithreading works, what to do and what not to do, and how to avoid CLR bugs... what yoy want more ? buy this book, have a quick read, and keep it on your desk.
If you still are not convinced, go to and read reviews...

Friday, 8 June 2007

Sql Server problem when attaching db with CLR objects

If you detach and then attach again, even if on the same server, a SQLServer 2005 database that has CLR stored procedures and functions you can receive the following message:

Msg 10314, Level 16, State 11, Line 1
An error occurred in the Microsoft .NET Framework while trying to load assembly id 65538. The server may be running out of resources, or the assembly may not be trusted with PERMISSION_SET = EXTERNAL_ACCESS or UNSAFE. Run the query again, or check documentation to see how to solve the assembly trust issues. For more information about this error:
System.IO.FileLoadException: Could not load file or assembly 'etere.playout.sqlserver, Version=, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An error relating to security occurred. (Exception from HRESULT: 0x8013150A)
at System.Reflection.Assembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection)
at System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
at System.Reflection.Assembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
at System.Reflection.Assembly.Load(String assemblyString)

MS says that only assemblies with UNSAFE or EXTERNAL_ACCESS are affected by the problem. The following MS knowledge base article explains the situation:,

I've tried to change the db owner as the article says, but it won't be working for me... maybe beacuse I was using TRUSTWORTHY ON. Don't know. Anyway I've tried to reissue the TRUSTWORTHY ON properties into the DB and... magic ! now works.

so if you are using the TRUSTWORTHY ON remember to include it after reattaching the db:

EXEC sp_changedbowner '?????'

Tuesday, 27 March 2007

Irritating one-sided policies by Microsoft applications ...

When you launch MS outlook it performs some action that may be really irritating... one of this is that it changes the default mailto action and associate it to outlook. I actually have 2 email clients on my desktop, we are migrating to outlook from novell groupwise, and I want to use groupwise until migration is complete... but once I launched outlook... no more mailto.... I've tried with several configurations such as the default mail application, but none has worked. So I've decided to change the mailto association directly inside the registry:
  • Go to HKEY_CLASSES_ROOT\mailto\shell\open\command
  • Change the value of the (Deafult) string
For outlook it may look like this: "C:\PROGRA~1\MICROS~2\OFFICE11\OUTLOOK.EXE" -c IPM.Note /m "%1"
for Novell groupwise it is something like that: C:\Novell\GroupWise\gwmailto.exe /%1

Now I'm happy :)

Wednesday, 21 February 2007

The GotDotNet site is being phased out

We are phasing out GotDotNet for the following reasons:
  • Microsoft wants to eliminate redundant functionality between GotDotNet and other community resources provided by Microsoft
  • Traffic and usage of GotDotNet features has significantly decreased over the last six months
  • Microsoft wants to reinvest the resources currently used for GotDotNet in new and better community features for our customers
well... what to say.. I was very affectionate to thE site, so this is a sad day for me. I will really miss the off topic discussion thread... how many heated debates there... hope that MS will open something similiar on his boards, even if I think it would never happen in a short time... at least not until they have such 'NAZI admins' (thanks to MStarr for his definition!!!)

Thursday, 8 February 2007

ASCII/Multibyte to Unicode conversion

I've just posted a new article on converting ASCII/Multibyte to unicode using C# and SQL/CLR Integration.
You can see it online on codeproject at the following address:

Wednesday, 7 February 2007

Kid's Programming Language

Do you enjoy programming and would you like that your children will do it too ? well consider to take a look to KPL (Kid's Programming Language): it is a freeware educational program developed by Morrison Schwartz, a software development and consulting company, with the following goals (extracted from KPL manual):
  • • We wanted to teach our own kids how to program
  • • We have fond memories of starting as programmers by coding games in BASIC
  • • Beginning programmers have been forgotten by the software industry for 20 years
  • • Specifically, VS.NET and Eclipse, the industry standard development environments, are NOT beginner environments Educational software could do much more for kids if it were easier to create, and with KPL it now is easier to create – even by teachers or parents who are not professional programmers
Another cite from TechWeb: "Microsoft has signed on to promote a new programming language intended to replace BASIC as the first step students take towards learning how to code. The Kid's Programming Language, or KPL, was developed under the direction of Jonah Stagner, and his colleagues, ex-Microsoft program manager Jon Schwartz and former NCR engineer Walt Morrison. The three run the software consultancy Morrison-Schwartz Inc. "

Monday, 5 February 2007

MS Robotics Studio

Robotics Studio is a Windows-based environment for academic, hobbyist, and commercial developers to easily create robotics applications across a wide variety of hardware.
The interesting thing is that within MSRS ships a technology called CCR:
Cite from Channel9 "The Concurrency and Coordination Runtime (CCR) is a lightweight port-based concurrency library for C# 2.0 developed by George Chrysanthakopoulos in the Advanced Strategies group at Microsoft. Here, we have a deep discussion about CCR with George, a Software Architect, and Satnam Singh, Architect. You can get more info about CCR on the CCR Wiki. This is super cool stuff and represents a really innovative approach to making managed threaded programming more readily understandable and predictable. "

How to setup Distributed Transaction Coordinator

The problem is really simple: You issue a query against a linked server and want to use transactions, but you get back an error, something like "The partner transaction manager has disabled its support" or "Distributed transaction coordinator has failed to ..."Ok, this is how you can set-up DTC to make distributed queries to work:

First verify the "Distribute Transaction Coordinator" Service isrunning on both database server computer and client computers
1. Go to "Administrative Tools > Services"
2. Turn on the "Distribute Transaction Coordinator" Service if it is not running.

If it is running and client application is not on the same computer as the database server, on the computer running database server
1. Go to "Administrative Tools > Component Services"
2. On the left navigation tree, go to "Component Services > Computers > My Computer" (you may need to double click and wait as some nodes need time to expand)
3. Right click on "My Computer", select "Properties"
4. Select "MSDTC" tab
5. Click "Security Configuration"
6. Make sure you check "Network DTC Access", "Allow Remote Client", "Allow Inbound/Outbound", "Enable TIP" (Some option may not be necessary, have a try to get your configuration)
7. The service will restart

On your client computer use the same above procedure to open the "Security Configuration" setting, make sure you check "Network DTC Access", "Allow Inbound/Outbound" option, restart service and computer if necessary.

On you SQL server service manager, click "Service" dropdown, select "Distribute Transaction Coordinator", it should be also running on your server computer.

Click here to see the MSDN thread with the original link by mornigsunshine.