debugger doesn't stop at breakpoint while debugging SQLCLR function

Hi,

I have created one simple SQL Server 2005 CLR function in Visual Studio 2005 beta 2. It works fine from SQL Server 2005 management studio April CTP.

When I try to debug this SQL CLR function from Visual Studio 2005, I am getting the output in Output window along with debug information but it is not stopping at breakpoint. Output window says ‘No symbols loaded’.

Could you please help me why it is not stopping at break point?

I checked configuration property and it is debug for project and solution. There is no Web.Conifg file, as it is Database project. So I changed the debug = true in machine.config file at all required places and restarted the PC.

I selected the function in Server Explorer -> Database connection -> Assembly -> Function1. Note that for this connection, Application Debugging and Allow SQL/CLR debugging options are already selected. I right clicked the function and selected ‘step into function’. Then it is displaying following message box.

“There is no source code available for the current location, and Ok and Show Disassembly buttons are displayed.”

If I right click the function in server explorer and click Execute, it is displaying the result in output window, but if I right click function and click Open it displays “ No output available for Object” message box.

In Debug mode, I went to Debug Menu -> Widows -> Modules and opened the Modules window. I located my module in Modules windows.

Then I right clicked and clicked Load Modules. I browsed the bin/debug folder of my project and selected the .pdb file then it gave the message “The symbol file SqlServerProject1.pdb does not match the module.”.

I went to Debug menu and clicked Attach Process and selected Sqlwb.exe process and then tried to execute function from SQL Server management studio but no success. In this debug mode, F10 and F11 are not working in visual studio, when Sqlwb.exe process is attached to debugger. When I hovered the mouse over the breakpoint in visual studio, it displays “The Breakpoint will not currently be hit. The specified module has not been loaded” tooltip.


Kindly let me know if I am missing something.


Thanks,

Amit.

[4150 byte] By [AmitJitendra] at [2008-2-7]
# 1
An answer to this would probably help me and others. It would be really cool if someone at Microsoft would try to answer some of the questions that noone else gives answers to. I have similar problems and can't seem to find the solution in any documentation. I really wish that these newsgroups could be more helpful to people who hit one of the myriad of uniformative error messages and can't find a solution in the documentation.
Mike12345 at 2007-9-9 > top of Msdn Tech,SQL Server,.NET Framework inside SQL Server...
# 2
Amit Jitendra wrote:

Hi,

I have created one simple SQL Server 2005 CLR function in Visual Studio 2005 beta 2. It works fine from SQL Server 2005 management studio April CTP.

When I try to debug this SQL CLR function from Visual Studio 2005, I am getting the output in Output window along with debug information but it is not stopping at breakpoint. Output window says ‘No symbols loaded’.

Could you please help me why it is not stopping at break point?

I checked configuration property and it is debug for project and solution. There is no Web.Conifg file, as it is Database project. So I changed the debug = true in machine.config file at all required places and restarted the PC.


You should not have to enter any debug information i any config files


Amit Jitendra wrote:

I selected the function in Server Explorer -> Database connection -> Assembly -> Function1. Note that for this connection, Application Debugging and Allow SQL/CLR debugging options are already selected. I right clicked the function and selected ‘step into function’. Then it is displaying following message box.

“There is no source code available for the current location, and Ok and Show Disassembly buttons are displayed.”



Is the project loaded in VS when you do the above? I.e. the project needs to be available in order to do this. You can also try and delete the connection in Server Explorer, re-create the connection and at the "Allow SQL/CLR debugging" option.


Amit Jitendra wrote:

If I right click the function in server explorer and click Execute, it is displaying the result in output window, but if I right click function and click Open it displays “ No output available for Object” message box.

In Debug mode, I went to Debug Menu -> Widows -> Modules and opened the Modules window. I located my module in Modules windows.

Then I right clicked and clicked Load Modules. I browsed the bin/debug folder of my project and selected the .pdb file then it gave the message “The symbol file SqlServerProject1.pdb does not match the module.”.



Your module file you choose above has nothing to do with this. All modules are loaded from the database.


Amit Jitendra wrote:

I went to Debug menu and clicked Attach Process and selected Sqlwb.exe process and then tried to execute function from SQL Server management studio but no success. In this debug mode, F10 and F11 are not working in visual studio, when Sqlwb.exe process is attached to debugger. When I hovered the mouse over the breakpoint in visual studio, it displays “The Breakpoint will not currently be hit. The specified module has not been loaded” tooltip.


Kindly let me know if I am missing something.


Thanks,

Amit.


The process you should attach to if you want to do this type of debugging is the sql server process; sqlservr.exe (I believe that's the name - I don't have a machine handy to check).
I suggest you rebuild your assembly, do a new deployment and tries again. Make sure your project is up and running when you try to do the debugging. If you do a "Step into ...." from server exploere you at least need the source file open in VS, and the source has to be the same as what's in the database.
I wrote a year ago a blog-entry about debugging, you can find it here. Be aware that it is fairly old though. I am writing an article at the moment for SQL Magazine about debugging, but that won't be published for a while yet.
nielsb at 2007-9-9 > top of Msdn Tech,SQL Server,.NET Framework inside SQL Server...
# 3

Hello,

Sorry to hear you are having trouble debugging SQLCLR code. Here is a quick walk through of how to do it.

Note: The config files should not be altered at all.

Setup:

1. Make sure that you have installed the VS Remote Debugging Components onto the SQL Server 2005 machine.

2. Execute the following SQL code to enable SQL CLR functionality.

Exec sp_configure ‘clr enabled’,1

Reconfigure

Example:

  1. Create a connection to SQL Server 2005 using NT Authentication. Making sure that your user name is an admin on the server box.
  2. On the server explorer connection enable “Allow SQLCLR Debugging” and “Application Debugging”. I like to enable both just incase I do app debugging at a later date.
  3. Create a new SQLCLR Project.
    1. Add a new SProc to the project. e.g. SProc1
    2. Add some sample code SProc1.
    3. From the solution explorer, open the TestScript.sql
    4. Add “exec SProc1” to TestScript.SQL
  4. Place a break point in SProc1.
  5. Start debugging From Project
    1. F5 or Start Debugging from debug menu.

OR

  1. Start debugging from Server Explorer
    1. Right Click on SProc1 and Step Into.

Tips:

1. You can manually run MSVSMON.exe on your SQL Server 2005 machine to see if debugging connections are made.

2. Running MSVSMON.exe once on both client and server machines can help sort out firewall problems. If MSVSMON.exe detects a firewall then it will offer to automatically change the settings to allow debugging.

RichMSFT at 2007-9-9 > top of Msdn Tech,SQL Server,.NET Framework inside SQL Server...
# 4

Thank you very much.

I am able to debug the SQLCLR function step by step using F10 and F11.

It seems remote debugging component was not installed during Visual Studio Installation. I installed the remote debugging component in VS.

When I expand the Database connection in Server Explorer, there is assembly for my Visual Studio project in Assemblies folder.

If I expand that assembly my function name is listed there. If I right click function name and click Open it is opening the source code for function in Visual Studio.

I click Step into Function and I am able to debug the function step by step.

Same Visual Studio project has stored procedure as well but it is not listed under above assembly.

Stored Procedure is in separate assembly which is created in SQL Server Management Studio. If I right click the Procedure in that assembly and click Open, I am getting message “No Source code is available for this object” message. If I click Step into Stored Procedure, it is not stopping at break point set in Stored Procedure.

Here is my Store Procedure

sing System.Data.SqlClient;

using Microsoft.SqlServer.Server;

public class FirstCLRProc

{

[SqlProcedure]

public static void HelloWorld()

{

SqlContext.Pipe.Send("Hello world! It's now " + System.DateTime.Now.ToString() + "\n");

using (SqlConnection conn = new SqlConnection("context connection=true"))

{

conn.Open();

SqlCommand cmd = new SqlCommand("SELECT AverageLeadTime FROM Purchasing.ProductVendor", conn);

SqlDataReader rdr = cmd.ExecuteReader();

SqlContext.Pipe.Send(rdr);

}

}

}

Could anybody please tell me why debugger is not stopping at breakpoint in above Stored Procedure? Note that break point is working fine for me for SQLCLR function.


Thanks,
Amit.

AmitJitendra at 2007-9-9 > top of Msdn Tech,SQL Server,.NET Framework inside SQL Server...
# 5
Amit Jitendra wrote:

Stored Procedure is in separate assembly which is created in SQL Server Management Studio. If I right click the Procedure in that assembly and click Open, I am getting message “No Source code is available for this object” message. If I click Step into Stored Procedure, it is not stopping at break point set in Stored Procedure.

Above you say the proc is in a separate assembly, creaed in SQL Server through SSMS. If that is the case, have you uploaded the debug symbols file as wel? That is needed if you want to debug:
ALTER ASSEMBLY name
ADD FILE path_to_pdb_file_inclusive_filename_and_extension

Hope this helps

Niels

nielsb at 2007-9-9 > top of Msdn Tech,SQL Server,.NET Framework inside SQL Server...
# 6
Thanks Niels.

I found the solution for the problem.

I created the SQLCLR stored procedure in Visual Studio 2005 Beta2.

Then I created the assembly in SQL Server 2005 by following commands in SQL Server Management Studio.

CREATE ASSEMBLY StoredProcedure1 FROM 'C:\StoredProcedure1.dll'

CREATE PROCEDURE HelloWorld

AS EXTERNAL NAME StoredProcedure1.FirstCLRProc.HelloWorld

Now when I go to Server Explorer in Visual Studio and expand the database connections, I get the Assemblies folder.

I found assembly with the name StoredProcedure1 and method HelloWorld inside that assembly.

When I right click the stored procedure and select ‘Step Into Stored Procedure’, it does not stop at the breakpoint and directly displays results in output window.

Solution:

I right clicked the project in Visual Studio and clicked Deploy.

Then I refreshed the Assemblies folder in Server Explorer, I got assembly with the Project name. Inside this assembly, I could locate my Store Procedure.

Now if I select the Stored Procedure method and click Open, it is opening the source code in Visual Studio. If I right click and select Step Into Store Procedure, debugger stops at first statement in that method and then I am able to debug the stored procedure one step at a time using F10 and F11 keys.

Thanks,

Amit.

AmitJitendra at 2007-9-9 > top of Msdn Tech,SQL Server,.NET Framework inside SQL Server...
# 7
Amit Jitendra wrote:

Solution:

I right clicked the project in Visual Studio and clicked Deploy.

Then I refreshed the Assemblies folder in Server Explorer, I got assembly with the Project name. Inside this assembly, I could locate my Store Procedure.

Now if I select the Stored Procedure method and click Open, it is opening the source code in Visual Studio. If I right click and select Step Into Store Procedure, debugger stops at first statement in that method and then I am able to debug the stored procedure one step at a time using F10 and F11 keys.


The reason it works is when you do an auto-deployment as per above, the debug symbols are deployed as well. This is the same as I said in my post above, about ALTER ASSEMBLY ....
Anyway, great that it works!!
Niels
nielsb at 2007-9-9 > top of Msdn Tech,SQL Server,.NET Framework inside SQL Server...

SQL Server

Site Classified