Hey there, was wondering if there's any way to cre...
# cfml-general
p
Hey there, was wondering if there's any way to create DSNs via a template, WITHOUT enabling RDS.
a
Yer aware you can just set them up in Application.cfc, yeah?
p
I am not! I'll check for some examples. But can a template be built that's not specific to an application?
a
I don't understand what you mean by "template"? You mean... like some code in a file?
p
Right. I apologize, not an expert. But I had a template that used the Admin API to create DSNs independently, if that makes sense. We've upgraded to CF 21 and it no longer works, because I believe RDS needs to be enabled. Which we don't want to do. So wondering if there's another way to do it.
a
OK cool I'm with ya. "template" is a bit of an old-skooly term for "a .cfm file with some code in it". Wasn't too sure that was what you meant. Trying to find you some good examples for setting 'em in Application.cfc... wherever the code needs to go, the data structure will be the same.
p
I mean, that IS what I meant - a CF page that can create DSNs independently. Is there a better way to refer to that than template?
a
So do you have like a mult-tenanted application or something, so lots of application roots (and accordingly lots of Application.cfcs) and want them... all... to have the same set of DSNs?
Well. These days one would want to keep as much code as possible out of .cfm files and in .cfc files. But if yer apps are .cfm-based, let's work with that.
p
So as part of my process, I just run a page that allows me to create DSNs, completely independent of anything else.
a
gotcha
p
Obviously the DSN won't verify at that point, but I'm not concerned with that.
a
In your situation I'd perhaps have one Datasources.cfc, and in that have a method that is
getDatasourceConfig
. And that returns the struct that an Application.cfc needs to create its DSNs on the fly. And you just reuse that Datasources.cfc. Does that make sense?
p
And if this needed to be a cfc file, or if it was just best practice that it was, that's fine. I think we mostly use cfms, but it's a mix.
Going back to creating a DSN within application.cfc, does it essentially just create it on the fly, whenever it needs it? It doesn't actually exist in the adminstrator?
a
So like in yer Application.cfc you have something along the lines of
Copy code
component {
    this.datasources = Datasources::getDataSourceConfig()
}
(Static method there, but you could also go `new Datasources().getDataSourceConfig()
It doesn't actually exist in the adminstrator?
Correct.
p
Is there a way to create it in the administrator without RDS, or is that not even really necessary?
a
Really these days you don't want to create them in admin.
Better to have "config as code" than need a special UI one needs to go into, or use adminapi calls using RDS etc.
p
So your suggestion would be to create them on a per-application basis, within application.cfc?
1
a
Indeed you might wanna look @ cfconfig. Makes all this stuff really easy and transparent. I'm not an expert in using it though (ping @bdw429s)
p
Okay, let me see if I can find a good example of that. I appreciate the guidance.
a
I can't find a good reference for "these are the settings you need for different kinds of DSNs". However this is this stackoverflow Q&A: https://stackoverflow.com/questions/16588539/create-datasource-in-application-cfc
I know this is a bit of scope-creep from what you asked, but using cfconfig for stuff like this allows yer config for yer entire app to be in code, so you can version control it etc. And you never need to use CFAdmin ever again, so you don't even need to expose it
If you wanna keep it simple for now and work on the Application.cfc approach, do ping back with questions. I'm about to turn in, but ppl in other TZs will be able to help.
p
Okay. And I was actually looking at that first link earlier. I'll investigate further, since that seems to be the way to go. Thank you.
a
NP fella.