[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 399
  • Last Modified:

Cold Fusion Database Connections and .NET Library

I know that within a Cold Fusion Administraton Page,  you can setup database connection info (host, user, encrypted--->pwd, etc.).  Can I use the database connection mechanism(s) from Cold Fusion in a .NET DLL that I have some business rules baked into?
0
Howard Bash
Asked:
Howard Bash
  • 7
  • 6
  • 3
  • +1
1 Solution
 
Kelvin McDanielSr. Developer/ConsultantCommented:
If I correctly understand what you're trying to do then you need to use CFObject (http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-789c.html).

If that's not what you're looking for then unless I'm mistaken you can't "liberate" the connection object for use outside of a .cfm context... Because that would be a whopping security hole.
0
 
OP_ZaharinCommented:
- there is no documented documents for such that i know. cf data source is not open publicly for other programming language to use unlike odbc admin manager in windows.
- however i'm sharing you a link, who able to do so via Java. maybe you can experiment a similar approach on .net
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
_agx_Commented:
(no points..)

I assume you mean connect to your db using CF's dsn? Probably not. But what would be the advantage over connecting through .net as usual?
0
 
Howard BashSenior Software EngineerAuthor Commented:
agx: my interest / advantage is that I have a class library (vs2008/vb.net) that I would like to use from within cold fusion.  this library connects to databases.  baking the connection into a library is often not useful and so the connection info is passed in to the library and would like to do the same with cf.
0
 
Kelvin McDanielSr. Developer/ConsultantCommented:
CFObject. If you're satisfied with doing your "work" in the dll then you're golden. Your only challenge then will be creating result sets that can be used natively (outside of the dll) by ColdFusion... If that is your aim.

Also, ColdFusion doesn't support dynamic connections anymore, at least not in an easy way... So you won't be able to return a connection string out to CF for use in a CFQuery. And, unfortunately, I'm not aware of any way to pass an ADO.NET connection context to and use by CF.
0
 
Howard BashSenior Software EngineerAuthor Commented:
It's the other direction regarding obtaining the connection string.  I want to obtain the string from CF within my DLL.   Of course I can (and do) pass the string in from the cf page,  but it would be nicer if I could have the connection retrieved from a cold fusion resource.
0
 
Kelvin McDanielSr. Developer/ConsultantCommented:
Understood. It simply isn't possible without brute-strength, unnecessary hacking and/or exposing potential attack vectors.
0
 
Howard BashSenior Software EngineerAuthor Commented:
OP_Zaharin: referred a URL with some java code.  I need to dig in to that bit before I surrender.
I'll get back with my findings.
0
 
_agx_Commented:
That's technically possible. I don't know about advisable..  You can obtain the dsn connection information though the Admin API.  But the dsn password is encrypted.  While it's possible to decrypt it, that may lessen security.

<cfscript>
    createObject("component","cfide.adminapi.administrator").login("The Admin Password");
    adminObj = createObject("component","cfide.adminapi.datasource");
    settings = adminObj.getDataSources("TheDatasourceName");
    WriteDump(settings);
</cfscript>
0
 
_agx_Commented:
You can obtain the dsn connection information though the Admin API.

.. or the java ServiceFactory class OP_Zaharin mentioned. Obviously you can pass the settings from cf => dll.  I don't know how easy it would be to access either object (cfc or ServiceFactory) one from _within_ your .net dll.  
0
 
Howard BashSenior Software EngineerAuthor Commented:
i need to connect to database(s) from within my .NET library.   So,  I need the ability to import some cf library or libraries to allow me to create coldfusion.server.ServiceFactory (I think).
0
 
_agx_Commented:
Oh, I thought you just wanted to get the connection string from the CF dsn. Then connect to your db as normal using .net connection objects.  Are you saying you want to actually connect to the cf dsn and run queries on it from _within_ .net?
0
 
Howard BashSenior Software EngineerAuthor Commented:
yes.  at most,  the cf  "client" page can pass the name of the connection.
0
 
_agx_Commented:
Ok, then I'm back to my original response.  I don't think it's possible, or at least not easily.  The ServiceFactory is an adobe class (not documented).  Unlike a .dll it's meant to run solely within a web app.  IF I'm remembering correctly, you can't just create one from scratch and have it be fully functional - even from java.  The factory needs the CF web context to function properly.  

So my guess would be it's not easily done. Even if it were, there's still the matter of compatibility issues and cost of conversion. From within CF it takes care of all the cf => .net conversions. I don't really know how that would be handled from the .net side.
0
 
Howard BashSenior Software EngineerAuthor Commented:
dlls are indeed used in web applications though.  additionaly the class library you mentioned "ServiceFactory"  appears to be made available by at least one third party component for java usage...

0
 
_agx_Commented:
No, I think you're misunderstanding. I'm responding to your earlier comment about creating a factory object from within .net. That's totally different than what's described in the earlier link.  The link talks about a referencing the existing singleton from within the same jvm where cf is already running.

ServiceFactory isn't a simple object you can just instantiate. It's meant to function within a web context and has many dependencies.  So grabbing a reference the singleton _after_ the CF service is up and running - from within the same jvm - isn't the same as creating the factory from scratch. Because all the hard work (creating the web context, creating other services, ..) is already done.

You might be able to grab a similar reference from w/in your dll. But I've no idea how or what you'd do with it once you had it there...
0
 
_agx_Commented:
appears to be made available by at least one third party component for java usage...

plenty of internal code might, but ServiceFactory is a proprietary class. so any code that uses it does so at it's own risk.
0

Featured Post

NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

  • 7
  • 6
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now