We are using SQL 2005 and the try-catch functionality to handle all of our error handling within the DB. We are currently working on deploying a .NET CLR function to make some WCF calls in the DB. This WCF procedure is written in the CLR and then deployed to SQL. If I put a try-catch block in the CLR code, it catches the error fine. However, I can't seem to throw the error up to the try-catch block in SQL. SQL seems to ignore what I throw it and catches the error it finds. Is there no relation between the two (i.e. I can't throw from one to another?)
If I can throw from within the CLR to the calling procedure in SQL, is any special formatting needed? I tried a specific case of catching the error that was thrown, and then throwing a different error, but SQL ignored my thrown error and caught the original error, as if it ignored the thrown error.
Here is a blog post that covers it at a highish level:
Exception handling in SQLCLR
When SQL server execute a user function/procedure/trigger implemented in CLR (i.e., managed code), we will install a managed exception handler around the user code. So if the user code leaked a exception, the server will catch it and throw a TSQL exception wrapping the user exception.
This seems to imply that it will just work.
Related
I am working on a VB.Net application. The application sometimes throws sql exceptions. Is there a way to pull the sql statement that threw the error? If not, what is a work around?
After googling out a lot this seems a unique situation hope I find answer to it.
Problem:
I am trying to execute a .net console application from SQL server using XP_CMDSHELL
For e.g
XP_CMDSHELL '\\sharedlocation\sharedfolder\dotnetconsoleapp.exe'
I am able to execute this successfully when I execute this exe from regular command prompt but face below error when i use XP_CMDSHELL to execute this console application.
The type initializer for 'Oracle.DataAccess.Client.OracleParameter' threw an exception.
Way of Implementation
Have a 3 layer architecture console application calling business layer and business layer calling Data Layer
Data Layer is using Oracle.DataAccess 4.112.3.0 from Add Referance -> Assembly -> Extensions
Using that dll I was able to execute stored procedure at Oracle 11G server
Error Recieved
The type initializer for 'Oracle.DataAccess.Client.OracleParameter'
threw an exception.
Please do let me know if I should have provided more information here.
Appreciate help from all techies here....
I am trying to execute on Impala a parameterized query from Pentaho (version 5.0.6) CDE using the ${parameter_name} notation. I found out that if I remove the parameter and I hard-code the value in the SQL query, everything works fine, but if I put the parameter, everything stops working with the generic error message "Error processing component" (I am using the table component of CDE to show the values). In the pentahobaserver-stdout log file I found the following exception:
Jun 24, 2014 3:01:08 PM com.sun.jersey.spi.container.ContainerResponse mapMappableContainerException
SEVERE: The exception contained within MappableContainerException could not be mapped to a response, re-throwing to the HTTP container
java.lang.NoSuchMethodError: org.pentaho.reporting.engine.classic.core.ReportDataFactoryException.getParentThrowable()Ljava/lang/Throwable;
Which seems to be a too generic error message (caused by this bug http://jira.pentaho.com/browse/CDA-79)
After some more investigation on the web, I think I bumped into this problem. For now I cannot avoid neither the use of parameters, nor the use of Pentaho nor the use of Impala, thus, I am stuck. Is there a workaround to this problem?
Thank you in advance :)
Not really. The JDBC driver for Impala does not support parameters in PreparedStatements which is what is used in the Reporting libraries.
It's a hard one to solve. Probably the best way to workaround it is to use a Kettle transformation that dynamically builds the queries and issues them to Impala.
That way, parameter handling will be done at the Kettle level, but for Impala it will be a static query.
I have a bunch of stored procedures which use RAISERROR to return to the client C# application certain business-logic error messages, and now I wonder if there is a way to localize these message in a way similar to .NET. Can these messages be localized somehow, or do they have to be hard-coded in the "main" language being used?
Side question: I have a .NET class library containing a resource file with strings. Can I use this dll from SQL Server 2005 and retrieve these error messages from that resource file?
SQL Server has localisation for the built-in system messages for many languages/locales.
For your own custom messages, you will have to catch and translate them in your application layer.
It 'might' be possible to use your .NET dll from SQL Server 2005 and retrieve these error messages from that resource file using a CLR Stored Procedure, but I wouldn't recommended doing it that way (it has permissions/deployment implications that are frankly best avoided).
Mitch indicated that the built in messages are localized. He didn't mention that you can use the same localization system for your own message. sp_addmessage lets you add new messages (and specify the language).
You then use the version of RAISERROR that uses a message number, rather than a message text.
I've just installed DB2 v8.1.18.980. Now I try to create new database. I'm getting the error with the following sql codes:
sqlcode : -902
sqlstate : 58005
Unfortunately the error itself in Russian, as a result, I cannot paste it here. Official site says the following about the problem:
"The statement cannot be processed. The application program is not permitted to issue additional SQL statements. For example, a recovery routine associated with the application program may not issue additional SQL statements.
Programmer response
Rebind the failing application program and try again. If the problem persists, examine your DBRM and make sure it matches your program."
http://publib.boulder.ibm.com/infocenter/dzichelp/v2r2/topic/com.ibm.db2z9.doc.codes/src/tpc/n902.htm
But, it's not clear to me. Any ideas, what can be wrong and how to resole it?
I'm using Windows 7 Ultimate if it may be an issue.
The documentation you linked to is for db2 v9 for z/os, not db2 v8 for Windows. So that's the first problem.
The documentation for v8 has this to say about SQL 902:
A system error (reason code = reason-code) occurred. Subsequent SQL statements cannot be processed.
Explanation:
A system error occurred.
User Response:
Record the message number (SQLCODE) and reason code in the message.
If trace was active, invoke the Independent Trace Facility at the operating system command prompt. Then contact your technical service representative with the following information:
Problem description
SQLCODE and embedded reason code
SQLCA contents if possible
Trace file if possible.
Federated system users: isolate the problem to the data source failing the request (refer to the Troubleshooting Guide to determine which data source is failing to process the SQL statement) and take the necessary diagnostic steps for that data source. The problem determination procedures for data sources vary, so refer to the applicable data source manuals.
sqlcode: -902
sqlstate: 58005
Which brings us to the second problem: it's asking you to contact IBM and open a ticket, and as far as I know v8 is out of support so it won't be that easy.
I think installing v9, v9.5 or v9.7 would be your best bet, unless you have a really compelling reason to stick with 8.