What is the best way to debug CLR stored procedures - sql-server

I have a fairly complex CLR stored procedure. What is the best way to debug the procedure? I would like to step through it if possible.

Google is your friend. Or more info in your post.
How to: Debug a SQL CLR Stored Procedure

Related

What databases which allow debug stored procedure?

While going through some online references on how to debug MySQL stored procedures, found that MySQL does not provide facilities for debugging stored procedures.
Can anyone educate me what are other databases which allows to debug stored procedures?

Prepared Statements and Stored Procs Used Together

I'm in the planning stages of a Microsoft ASP.NET / SQL Server 2008 based web application and In thinking about database design, I began to think about injection attacks and what strategies I should employ to mitigate the database as a vector for injection attacks.
I've heard from various sources that using stored procedures increases safety, I have also read that these are equally as infective if they are still used with dynamic SQL as this presents an injection point
Question
Is it possible to use a Parametrized Query inside a stored procedure? My thinking is that if I pass the arguments to the stored procedure into the prepared statement the database engine will sanitize those arguments for me.
Yes you can pass Parametrized query inside a store procedure.
but it think it will not use execution plan in the procedure
and work slow as per my knowledge.

Thoughts On Extended Stored Procedures

I am looking to insert and update records in a database using functions and logic that are not available in SQL Server or any other RDBMS for that matter. After Googling around a bit this morning, I have come across the concept of Extended Stored Procedures. As far as I can tell, I should be able to compile my desired functionality into a dll, make a stored proc utilizing that dll to do the inserting/updating.
However, most of the articles and examples I have come across are somewhat dated (~2000). Are extended stored procedures still an acceptable practice? I am far from an expert in this area, so any other suggestions or comments would be greatly appreciated.
If you're using SQL Server 2005 or later, SQL CLR is the area to look at. You can call .NET code from within SQL Server.
This article on MSDN is a good place to start.
Are extended stored procedures still
an acceptable practice?
No, they are officialy deprecated and will be dicontinued in a future release. See Deprecated Database Engine Features in SQL Server 2008 , in the Features Not Supported in a Future Version of SQL Server table:
Extended stored procedure programming: Use CLR Integration instead.
I usually recommend against using CLR procedures, in most cases you can refactor the problem you are facing, into something that Transact Sql can handle.
Of most concern is the procedural approach that often accompanies the use of CLR procedures, when a relation database performs best when performing set based operations.
So the first question I always ask, is there anyway to refactor the problem into a set based operation.
If not, then I ask why would you want to execute the code inside of the database server, instead of in an application layer? Think about the performance impact you might have by placing the logic inside the database. (This might not be an issue if your db server has plenty of extra processing time).
If you do go head with CLR procedures, I think they are best applied to intensive calculations and complex logic.

How to use Stored Procedure in SqlCE

I have just installed Sql Server Compact Edition. To my surprise, we can't use stored procedure in sql server CE. Do I have any alternative of Stored Procedure in Sql Server CE.
I am strongly obsessed with stored procedure, I can'nt think of an application without stored procedures.
Please help, Thanks in advance.
Edit: Can I use Managed Stored Procedures.
SqlCe is a local database for use by an application. There is no need for stored procedures since the database is just a local data store, and the business logic is in the application. It is not an engine. If you need an engine then use SqlExpress or its big brother. See Steve Lasker's Comparing SQL Server Express and Compact Editions Whitepaper at http://download.microsoft.com/download/A/4/7/A47B7B0E-976D-4F49-B15D-F02ADE638EBE/Compact_Express_Comparison.doc. It explains everything you need to know.
No, you cannot use managed stored procedures. SqlCe is in-process.
Also, you might find Data Storage Architecture with SQL Server 2005 Compact Edition at http://msdn.microsoft.com/en-us/library/bb380177(SQL.90).aspx helpful.
This blog from Steve Lasker describes how you can implement something similar to sprocs on SQL Server Compact: http://blogs.msdn.com/stevelasker/archive/2008/02/11/stored-procedures-and-sql-server-compact-the-great-debate.aspx
You will have to use inline sql in your application. Use SqlCeCommand.CommandText Property to specify sql text.
I don't really know what is supported by SQL Server CE, but UDFs can often be substituted for stored procedures. If that doesn't help, try calculated columns and/or indexed views. If those are not available as options, then I think you are stuck with putting the logic in your application.

SQL Server stored procedure question

I have a SQL Server stored procedure which has been in use for years. This stored procedure calls lots of other procedures. I would like to extract each inside procedure one at a time and implement its business logic to a .NET Class project.
In order to do that, I have to call .NET assembly from parent stored procedure and the returned result will be used by parent procedure. Since SQL Server 2005 and higher has CLR integration, so I think, executing .NET assembly inside stored procedure [or any Database objects] should not be a big deal, can you please point me some references where i can find examples or article to implement it?
Thank you very much for your help .
I really feel that this would be an inappropriate use of SQL CLR. The purpose of CLR integration is to support complex data types and operations that are normally very hard to do in pure SQL (such as sequences, regular expressions, hierarchy, geospatial, etc.) Not to implement a domain model in your database.
Domain models and business logic are separate from relational/data models. They should be in a proper business tier of some sort. Don't hack them into a database using the CLR.
(Note: I use SQLCLR a fair bit. I am not railing on CLR integration. I just don't think that this question reflects a wise design decision.)
MSDN
Building my First SQL Server 2005 CLR
An Intro to CLR Integration in SQL Server 2005
For loads more ;)
I think you should use SQL Server Integration Services (SSIS). As far as I understand, it solves this case, to orchestrate the procedure calls and gives you much more too..
I'm not too sure if moving this decision outside the db layer is a good decision.
Hope it helps..

Resources