Partilhar via


How to: Deal With Attach Errors 

This topic applies to:

Visual Studio Edition

Visual Basic

C#

C++

J#

Visual Web Developer

Express

No

No

No

No

No

Standard

Yes

Yes

Yes

Yes

Yes

Pro/Team

Yes

Yes

Yes

Yes

Yes

When the Visual Studio debugger attaches to a running process, the process can contain one or more types of code. The code types the debugger can attach to are native, managed, T-SQL, and script. These code types are displayed and selected in the Attach to Process dialog box.

NoteNote

For the debugger to attach to managed code written in C++, the code needs to emit DebuggableAttribute. You can add this to your code automatically by linking with the /ASSEMBLYDEBUG linker option.

Sometimes, the debugger can successfully attach to one code type, but not to another code type. This might happen if you are trying to attach to a process running on a remote machine. The remote machine may have remote debugging components installed for some code types but not for others. It can also happen if you try to attach to two or more processes for direct database debugging. SQL debugging supports attaching to a single process only.

If the debugger is able to attach to some, but not all, code types, you will see a message box with a message similar to this:

The requested attach was not completed successfully.
Program types successfully attached are:
Common Language Runtime
Native (Win32)
Microsoft T_SQL
Program types that failed to attach are:
Script

If the debugger successfully attaches to at least one code type, you can proceed to debug the process. You will be able to debug only the code types that were successfully attached. The example message above shows that the script code type failed to attach. Therefore, you would not be able to debug script code within the process. The script code in the process would still run, but you would not be able to set breakpoints, view data, or perform other debugging operations in the Script.

If you want more specific information about why the debugger failed to attach to a code type, you can try reattaching to only that code type.

To obtain specific information about why a code type failed to attach

  1. Detach from the process. To do so, on the Debug menu, click Detach All.

  2. Reattach to the process, selecting only a single program type.

    1. In the Attach to Process dialog box, select the process in the Available Processes list.

    2. Click the Select button.

    3. In the Select Code Type dialog box, select Debug these code types and the code type that failed to attach. Clear any other code.

    4. Click OK. The Select Code Type dialog box closes.

    5. In the Attach to Process dialog box, click Attach.

    This time, the attach will fail completely, and you will get a message box with a specific error message.

See Also

Other Resources

Attaching to Running Processes