WR Vishnu Coldfusion Weblog

Blog for Coldfusion and Coldfusion related technologies….

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

17 Responses to “Coldfusion & .Net Integeration”

  1. vincentcollins Says:

    Thanks for contributing! I hope to see more!

  2. Todd Rafferty Says:

    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.

  3. bethb Says:

    Thanks for this post. Looking forward to more on this topic!

  4. wrvishnu Says:

    Yes , will try to put few more sample for coldfuaion and .net

  5. wrvishnu Says:

    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

  6. ARINDAM Says:

    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

  7. W.R.Vishnuprasda Says:

    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

  8. Teju Says:

    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

  9. W.R.Vishnuprasda Says:

    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

  10. Teju Says:

    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

  11. ARINDAM Says:

    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

  12. W.R.Vishnuprasda Says:

    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

  13. ARINDAM Says:

    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

  14. Teju Says:

    Thanks for the help
    I have missed the root namespace while calling the class

  15. James Says:

    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

  16. vishnuprasad Says:

    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

  17. Andrew Scott Says:

    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 :-(

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>