How can I programmatically delete a datasource in ColdFusion - coldfusion

[RESOLVED]
I have a C# program which interfaces with ColdFusion by running a CFM file.
One of the tasks of the CFM file is to create three datasources in ColdFusion. This works well.
The issue I am dealing with is that I have a requirement to use the same methodology in order to delete a datasource. According to Adobe's documentation this function is available, but I cannot find any examples of this on the WWW.
Can anyone here guide me as to how to remove a ColdFusion datasource using code within a CFM file?
Thanks in advance.
Regards,
Ken.
As pointed out by Alex, I really should have included the ColdFusion version number. Version 11.
The working resolution inspired by Ageax's answer is:
<cfscript>
adminObj = createObject("component","cfide.adminapi.administrator");
adminObj.login("#URL.cfpw#");
myObj = createObject("component","cfide.adminapi.datasource");
myObj.deleteDatasource("#URL.ds#");
</cfscript>
I have posed my code here, only because this is the code I actually used and tested.

You can programmatically call the CF Admin API. I believe you can do something like this inside a ColdFusion file.
<cfscript>
/* Connect to CF Admin API */
dbConnection = CreateObject("cfide.adminapi.administrator").login("adminPW","adminUser");
if (dbConnection) {
/* Instantiate datasource object */
ds = createObject("cfide.adminapi.datasource");
/* Delete the datasource */
ds.deleteDatasource("myDatasourceName");
}
</cfscript>
Note: I don't currently have a CF server that I can test on, so please double-check me.

Related

Referencing code-created datasources in Lucee

I have created a number of datasources in Lucee using code. This is for a legacy ColdFusion application that we are migrating to Azure, and per the powers-that-be, they want the DSNs created in code so we can store the DSN passwords in a keystore. I have that part already working.
The datasources look something like this: this.datasources["myDSN"]
If, in the code (Application.cfm), I do this:
<cfset myDSN = this.datasources["myDSN"]>
This will then fail:
<cfquery name="whatever" datasource="#myDSN#">
It fails with "datasource myDSN not found."
BUT, if I do this instead:
<cfquery name="whatever" datasource="#this.datasources['myDSN']#">
... it works fine.
Is there a workaround for this? At last check in this one application alone, there are 368 occurrences of datasource= in 115 files. I'd rather not have to do a bulk search/replace. It makes no sense to me that the variable "myDSN" would fail.
As there are multiple datasources being used, I can't just set the default datasource and remove the datasource= attribute entirely; even then, it'd still require a mass search/replace.
I must be missing something. I've read the Lucee docs on datasources but it hasn't helped. Thanks!
Turns out that Scott Stroz was correct. I switched over to Application.cfc and now it works fine.

CFCLIENT: Doc examples do not work; Can't get anything to work?

So I realize that the new CF11 mobile features have been received with some very mixed reviews, but I wanted to try them out to see if I could use them for some really simple device detection, however I cannot get anything to actually work.
For example, I am looking at the doc for cfclientsettings, specifically at the first example on the page under the "Device detection" heading. Here's the code for reference (I formatted it a little to ensure it's easy to read here):
<cfClientSettings detectDevice=true />
<cfclient>
<cffunction access="public" name="showCanvasSupport" returntype="void">
<cfset evalStr = "document.getElementById('canvas').innerHTML='" & cfclient.canvas & "'">
</cffunction>
</cfclient>
Canvas support -<b id="canvas"></b><br>
<button onclick="invokeCFClientFunction('showCanvasSupport',null)">Show canvas support</button>
Creating a new .cfm page and adding this code produces the text and button on the page, but clicking the button throws a JS error in Chrome: "Uncaught The function signature is invokeCFClientFunction(functionName [, arg1, arg2, arg3, ...], successCallback, failureCallback). The functionName, successCallback and failureCallback are mandatory. If you don't have a successCallback or failureCallback, null can be passed as the value."
Ok, not great. So I checked some more docs and decided to add another null argument to the invokeCFClientFunction() call to fix the missing callback. This at least corrects the JS error, but now nothing at all happens when clicking the button.
So after some more fussing, I arrived at the following code, which still does not work, but seems closer:
<cfClientSettings detectDevice=true />
<cfclient>
<cffunction access="public" name="showCanvasSupport" returntype="void">
<cfscript>
document.getElementById('canvas').innerHTML=cfclient.canvas;
</cfscript>
</cffunction>
</cfclient>
Canvas support -<b id="canvas"></b><br>
<button onclick="invokeCFClientFunction('showCanvasSupport',null,null)">Show canvas support</button>
So this code, when you click the button, sets the innerHTML of the canvas element to "undefined". Awesome.
Honestly, I've been trying every example I can find for using cfclient and NONE of them work. Is there some secret I'm missing? I have a sneaking suspicion that if I'm not creating a 'Mobile Project' in CFBuilder that this stuff doesn't work? If so that's stupid and they don't state that in the docs really.
What I'm trying to do, in the end, is simply use cfclient for some basic device detection and to grab the width of the browser/device to do some basic media query style detection very much like in the "Using media queries" section of the cfclientsettings doc. I just want to grab the width and then set a session variable based on it.
I am running a fully patched developer version of CF11 on my Win7 machine setup with IIS. Any and all support is welcome.
Cross post on Adobe Forums: https://forums.adobe.com/thread/1929387
After bashing my head on my keyboard for a while more, I've gotten the cfclient scope working.
I finally found this page in the docs: Device Detection
At first glance, this page seems almost identical to the cfclientsettings doc page, even having the same code examples.
However, where the cfclientsettings doc uses the scope like this:
cfclient.canvas
The Device Detection doc page writes it like this:
cfclient.properties.canvas
Boom. That's of course all it took. What a waste of time. All the cfclient scoped variables work just fine if you add ".properties" in there.
I'm still not sure if the cfclientsettings doc is just plain wrong, or if it's referencing it in a different context. I'll definitely add a comment to it on that point.
(Also, the JavaScript still fails for this example on both doc versions, so there's that.)
Hope this helps somebody who wants to do simple ColdFusion client device detection.
Let me preface this answer by stating that I have never used cfclient and I am only relaying the documentation that I found online for it's use. This was too long for a comment.
You stated:
I have a sneaking suspicion that if I'm not creating a 'Mobile Project' in CFBuilder that this stuff doesn't work? If so that's stupid and they don't state that in the docs really.
I think they do state that in the documentation actually. Here is what I found. At the beginning of the Client-side CFML (for mobile development) document it states:
Before you begin – To try out the examples provided in this document, you need to set up the ColdFusion mobile development environment. See Configuring the development environment.
I am not going to repeat all of the information here as it is fairly substantial but the Configuring the development environment page mentions that you must install ColdFusion Server 11, install ColdFusion Builder and then create a 'ColdFusion Mobile Project' within Builder to help you along.
However that page also states that you can convert an existing ColdFusion project automatically by following the steps under Migrating existing projects where you 'Apply CF Mobile Nature' to the project from within ColdFusion Builder. This may be the piece that you are missing.
I think if you read through the documents that I referenced it may get you going. Also here is a link to their Building Mobile Applications documentation which contains an overview of the entire process.

Can't refresh CFC CF9 when using an application.cfm

I was charged with making some modification to an old application, and I created a new page which was being passed a URL parameter page_name, which is a you guessed it a name of a page with .cfm appended. So, in my haste, I continued using it, and was building out my CFC and using the page_name as the identifier for a record. Then I realized that there is a possibility of that name being duplicated in the table, and changed that url parameter to use the page_id, which is unique. I modified my CFC to use the new key, and nothing worked. So I started going through my code and figured I made a typo, started commenting things out, and finally dumped out my CFC object and voila, none of the edits I made were actually being used. This was fairly obvious, since page_name was a string, and page_id was numeric.
So I started googling,The first thing I saw as adjust things in the CFAdmin. I don't have access to it, and restarting the server isn't an option since I'm using an RDS to live code. The next thing I tried was to add applicationStop(), onApplicationStart(), to my Application.cfc. Well the problem is that the Application.cfc, is actually an Application.cfm. So after fiddling with the <cfapplication ... > tag, and nothing being updated, I'm here asking for help.
So is there a quick fix for this? Should I go ahead and create an application.cfc? I hope I explained myself, and sorry for all the text.
Confirm that your cfc is bound to either the session or application scope.
If it is, then you can rename the application in application.cfm and it will reset the object.
If your cfc is NOT bound to session or application scope, you have a cacheing issue. You need to go the the CF admin -> Server Settings -> Cache tab and uncheck component cache and possibly some others.
For further recommendations, ColdFusion Components Inheriting Functions Of Others
Sounds like you have been painted into a corner. Last option IF you have access the the server it self and can get into the C:\ or whatever drive that ColdFusion have been installed on, you can just manually delete the generated Java Class files that the server is using that has the old code. When ColdFusion sees there is no Class file it will recompile the newly changed file and whoa black betty go bam-a-lam your changes will be in production.
For more information here is an posting you can read up on: http://kalyan-coldfusion.blogspot.com/2010/08/how-coldfusion-works-and-its-key.html
Cheers

Translate xml content using web service API from Ektron CMS400.Net

First of all: I'm on Ektron CMS v8.1
I'm having a problem with dynamicly adding translated content to the cms via the Webservice API. I can perfectly add xml content by using the following object and method:
ContentSoapClient csc = new ContentSoapClient("ContentSoap");
csc.AddContent3(...);
I specify a language and the xml content gets inserted. But now I want to add a translated version of the xml to the cms. So I want it to have the same contentId!
Anyone has an idea on this? The only method in the csc object that recieves a contentId is 'csc.AddContent2(..)' But that doesn't import anything and just gives me an error saying my xml is incorrect. While my xml is correct..I checked it!
Thanks!
Found the answer..
Ektron apparantly uses alot of asmx files and I only checked the "/workarea/webservices/WebServiceAPI/Content/Content.asmx" webservice. I found the method 'AddTranslatedXMLContent()' I need in the "/Workarea/webservices/ContentWS.asmx" webservice.
I wish they just cleaned up their API... Would save us a lot of trouble.
Firstly, I haven't used the ContentSoapClient class and can't find any documentation on it.
Ektron often takes a language id when you create the API object. See if the ContentSoapClient contructor can take a Language Id.

ColdFusion Google Adwords Business Component Error

I am using Martin Orth's ColdFusion API for Google Adwords. I have been able to fix some errors to get the API working in most cases, but am running into a roadblock when I try to use the business.cfc component. I try to create the component the same way I have successfully created them for other components of the API with the syntax:
cfset oBusiness=createObject("component","com.google.adwords.api.v12.business")>
The results in a:
coldfusion.xml.rpc.CFCInvocationException: [java.lang.ClassNotFoundException : com.google.adwords.api.v12.business][coldfusion.runtime.CfJspPage$NoSuchTemplateException : Could not find the ColdFusion Component or Interface long.]
even though the business.cfc file is located as the specified path and has not been modified. Has anyone been able to get this component to work? If so, can you post a copy of your business.cfc file? Thanks in advance.
I just rewrote the entire code minus comments and hints (in past files there were many illegal chars) in a new file and it worked fine.
There is a new version (V201101) of the AdWords API library for ColdFusion at http://www.cfsolutions.de/coldfusion_adwords_api/docs/index.cfm