Archive for the ‘.Net’ Category

Using Ref Cursor with Oracle’s ThinClient JDBC driver and Coldfusion via .Net

Tuesday, May 10th, 2011

So it’s a known issue that Coldfusion does not support returning a ref cursor as an out parameter of a stored procedure when using the Oracle Thin Client drivers. Since I have experienced this problem in the past I thought I would post a solution that uses C# to manage the Oracle stored procedure and return the result set to Coldfusion. So this solution will use Coldfusion’s ability to create object instances of a C# class using the ‘cfobject’ tag or the ‘createObject()’ function. Also keep in mind that if Coldfusion is returned a type DataTable from the C# method it will automatically convert it into a Coldfusion Query object that can then be handled like normal. So with this in mind let’s take a quick look at a basic Oracle stored procedure and the C# class that will execute the procedure and return a DataTable object.

Oracle Stored Procedure

create or replace
PROCEDURE "SP_TEST_CF9"
(
      arg_ArgumentOne IN NVARCHAR2,
      l_cursor OUT sys_refcursor
)
AS 

BEGIN

      OPEN l_cursor FOR
      SELECT column_name, column_id
      FROM  column_table
      WHERE column_argument_one = arg_ArgumentOne;

END SP_TEST_CF9;

(more…)

“Can’t Find Class” when calling a .Net .dll with Coldfusion

Tuesday, May 3rd, 2011

**Synopsis (in case you don’t want to read my story below) :: If you’re running CF9 and .Net Framework 4 and getting an error that indicates that the given class cannot be found in the given assembly it is likely that you need to upgrade your Coldfusion to 9.01 and restart both CF and .Net services.

I’ve been doing some ongoing research lately concerning the ability of CF to execute .Net classes. I’m running CF9 and .Net Framework 4. I began by calling the built-in .Net method GetHostName() that simply returns a string of basically the computer name.

Calling a Built-In .Net Class

<cfobject type=".NET" name="variables.test" class="System.Net.Dns" action="create" />
<cfset variables.hostName = variables.test.GetHostName() />
<cfoutput>
	#variables.hostName#
</cfoutput>

Worked perfect. What a great start! I’ve essentially just executed a .Net method with Coldfusion in less lines of code than I could have done writing a C# class. Excellent. So at this point I thought it was time to execute a class written and compiled by myself. I can’t remember my exact test, but it was something very simple that just returned a string like the following.

Simple C# Class

namespace testClass
{
    public class Test
    {
        public String returnName()
        {
           return "Matt";
        }
    }
}

I compiled the class into a .dll and saved it to somewhere easy to get to like the desktop. I then wrote a similar cfobject tag to call this like the following.

Coldfusion Caller

<cfset variables.pathToDll = "/Desktop/classLibrary/myClass.dll" />

<cfobject 	type = ".NET"
			name = "variables.test"
			protocol = "tcp"
			class = "testClass.Test"
			assembly = "#variables.pathToDll#"
			action = "create"
			secure = "false" />

Executing this code returned an error indicating that the class ‘Test’ could not be found in the selected Assembly. This was good news and bad news. The good news was that it found my Assembly. The bad news, obviously it couldn’t find the class.

After several hours of trying things and research I finally found that the .Net Framework 4 support was introduced in the CF9 Update 1. A quick check revealed that I was indeed not running 9.01. I upgraded, restarted both CF and .Net services and everything worked!

Showing line numbers in Visual C# 2010 Express

Thursday, July 15th, 2010

Thought I would share how to show line numbers for the code editor in Microsoft Visual C# Express because it is less than intuitive.  My personal opinion is that the numbers should show by default.  It makes a ton of sense to display error locations by line number, but not actually show the line numbers in the code editor.

Anyways, in the top navigation open tools > options dialog.  In the dialog make sure you first check the ‘Show all settings’ checkbox in the lower left corner.  Now expand the ‘Text Editor’ menu item.  Click ‘All Languages’.  Lastly check the ‘Line numbers’ checkbox in the options.  It should really not be this complicated.