Coldfusion & .Net Integeration
Posted by wrvishnu on September 12, 2007
This is a sample code snippet for Coldfusion and .Net intgeration
To access the .net methods first we need to create an object for the .Net Class , after creating the object we can access the methods in that class . Following is a sample code snippet for accessing the .net methods from coldfusion
Steps to work on the samples
Step 1 Copy the Access MDB file into the “D:\LEarning\CFDotNet\Northwind.mdb”
Step 2 Create the .Net Class Library in Visual studio 2005 , below is the code snippet
// This Code is developed in .net 2005
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Collections;
using System.Data;
using System.Data.OleDb;
using System.Data.SqlClient;public class CfSample{
public CfSample()
{
}
public int SampAdding(int a, int b)
{
int c;
c = a + b;
return c;
}
public int SampSubtract(int a, int b)
{
int c;
c = a - b;
return c;
}
public int SampMultiply(int a, int b)
{
int c;
c = a * b;
return c;
}
public DataTable ACCdatasetMethod()
{
//conn string
string connectionString = “Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\\LEarning\\CFDotNet\\Northwind.mdb” ;
//ConnectionString=’//connection
using (OleDbConnection connection = new OleDbConnection(connectionString))
{
OleDbCommand cmd = new OleDbCommand(@”SELECT [EmployeeID], [LastName], [FirstName], [Title], [City], [Address], [HireDate], [BirthDate], [TitleOfCourtesy], [Region], [PostalCode], [Country], [HomePhone] FROM [Employees]“, connection);
connection.Open();
OleDbDataReader reader = cmd.ExecuteReader();
DataTable dt = new DataTable();
dt.Load(reader);
return dt;
}
}
}
Step 3 Compile the Visual studio solution
Step 4 Copy the generated DLL file in any path or can use the same path where it got generated
Step 5 Call the .Net method in Coldfusion
<cfobject
type = “dotnet”
name = “MDBDTable”
class = “CfSample”
assembly = “D:/vishnu/CfSample.dll”>
<cfset query11 = MDBDTable.ACCdatasetMethod()>
<cfdump var=”#query11#”>
Please get the sample files from the location http://www.drivehq.com/folder/p2544729.aspx
September 12, 2007 at 12:58 pm
Thanks for contributing! I hope to see more!
September 12, 2007 at 5:16 pm
I look forward to more .net/cf examples! Maybe something using http://www.websitescreenshots.com/? If you buy the pro version, it has a webshot.dll with it that you can utilize.
September 12, 2007 at 6:06 pm
Thanks for this post. Looking forward to more on this topic!
September 13, 2007 at 2:49 am
Yes , will try to put few more sample for coldfuaion and .net
September 13, 2007 at 2:52 am
Hi Todd Rafferty
AS a start i am working on creating APi for taking screenshot of the current window , and save as image in desktop
Once that is done will post the same in this blog
January 31, 2008 at 12:27 pm
Hello Sir,
the example is working fine in CF 8 and Visual studio 2005 ,but not in in Visual studio 2003 . It shows the error Class CfSample not found in the specified assembly list. The assembly that contains the class must be provided to the assembly attribute . Please give your suggestion and is it possible o integrate CF8 and Visual studio 2003 .Its urgent .
Thanks
Arindam
February 1, 2008 at 5:30 am
Hi
yes it possible to integrate CF 8 with VS2003 , i have sent you the steps to this email id arindam_parida(st)(rediffmail)(dot)(com)
what is ur contact number
February 1, 2008 at 6:20 am
I created a.NET 1.1 dll using your specified logic but it throws error when I callled the .Net dll from CF8.
“It shows the error Class CfSample not found in the specified assembly list. The assembly that contains the class must be provided to the assembly attribute .”
Do I have to change the settings to integrate CF8 with .Net1.1
Your example is working fine with .net 2.0 dll.
In CF8 documents, it says CF8 can be integarted with .net 1.x, 2.x and 3.x
Please reply soon. Its urgent
February 1, 2008 at 6:39 am
Hi
Have u delete the old DLL and stop the coldfusion 8 .Net service and move the new DLL
If you have done those steps , it will work fine .
r u online in yahoo or Gtalk , if yes u can add me , i can guide u the steps that needs to be followed
Gtalk : wrvishnu
yahoo : dropin_vishnu@yahoo.co.in
February 1, 2008 at 7:08 am
yes I have done all mentioned steps.
Delete the old dll.
Uninstalled .Net2.0 framework,
then Installed .net1.1 framework
then installed Cf8.net services.
restarted the system
Still getting same error
Iam online on gmail and have given invitation for chat to u.
Thanks
Teju
February 4, 2008 at 6:04 am
Hi,
can we pass xml from ColdFusion to .net ? If yes please give an example . My first problem connection with CF to .Net 2003 is solved .
Thanks
Arindam
February 4, 2008 at 7:26 am
DO you want to pass XML from Coldfusion to .Net or
.Net to Coldfusion
What is your contact number
DO u have Gtalk or yahoo messenger
If yes whats ur id
mine
yahoo IM :dropin_vishnu@yahoo.co.in
Gtalk : wrvishnu@gmail.com
February 4, 2008 at 7:52 am
Hi,
I want to pass xml from CF to .net . I am new in CF . So please
give an example how to pass xml from CF to .net . I don’t have Gtalk ar yahoo messanger . You can give the example in my rediff
id .
Thanks
Arindam
February 4, 2008 at 7:57 am
Thanks for the help
I have missed the root namespace while calling the class
February 5, 2008 at 5:08 pm
After a good amount of trial and error, we have been able to pull back data from a simple .NET class. The problem that we seem to be having is that unless the .NET connectionString is hardcoded into the class then it won’t seem to work.
The connectionString is refered thus:
string connectionString = ConfigurationManager.AppSettings["sqlDatabaseServer"];
Do you (or anyone else) know if we can use the referenced connectionString or if it has to be hardcoded into the class
Thanks
February 6, 2008 at 12:48 am
Hi
So far i have tried only using hardcored values , can you try to pass the connection string values a parameter from cf8 to .Net
April 16, 2008 at 12:29 am
Class au.com.aegeon.asReportTool not found in the specified assembly list.
Has this bug / problem been identified? I am getting it and googled to find nothing that can help the situation.
It works fine if it is run on the same machine VS 2008 is on, but will not work on the server it is intended for