Get DSN

How can I get the DSN from the ColdBox.cfc file?

//Datasources
datasources = {
dsn = {name=“air40dbadev”, dbType=“oracle”}
};

I am sure it is simple but I am just getting started with ColdBox. I have a lot of learning to do.

in all your DAO and gateway Files you will need to add

Okay then what do I use for the Datasource=""?

#instance.dsn#

Application Execution Exception
Error Type: Expression : [N/A]

Error Messages: Element DSN is undefined in INSTANCE.

What could I have done wrong?

or #dsn.getName()#

Should it be

or

I tried both and get the same error. What could I be doing wrong?

did you “reinit” you app?

  • Gabriel

Yes, I did.

Have you enabled and configured Wirebox?

This should work for you.

  1. Make sure you have an inject annotation on your component declaration.
  2. Add this property: property name=‘DSN’ inject=‘coldbox:datasource:mySite’;
  3. Add to your query: datasource="#DSN.getName()#".
    You can dump the variables scope to see the DSN object if your injection is working as expected.

Aaron Greenlee

@QuackFuzed
I have not configured Wirebox - Is this what I have to have? or is that just another choice? I don’t mind trying that as a second choice.

@Aaron Greenlee
What exactly do you mean by Step 1?

I added this

In the query I added this

datasource="#DSN.getName()#">

It seems to not be working still.

You need to have some sort of DI engine enabled and configured in order to have things injected. So check the docs for either Wirebox or ColdSpring setup/configuration.

I would review Aarons response as it has each of the steps to:

  1. Config the dsn and name to reference it by (in coldbox.cfc)
  2. Inject it
  3. Reference it after injected

Wirebox should be enabled by default.

Nolan Dubeau

Load .,8,1

Would it not be?

property name=‘DSN’ inject=‘coldbox:datasource:air40dbadev’;

#dsn.getName()#

Nolan Dubeau

Load .,8,1

Yes, given his configuration it would actually be “property name=‘DSN’ inject=‘coldbox:datasource:air40dbadev’;”.

Step 2 - Add the property to the Gateway.cfc correct? it is still not working.

In ColdBox.cfc

//Datasources

datasources = {

dsn = {name=“air40dbadev”, dbType=“oracle”}

};

In the object Gateway file

<cfproperty name=‘DSN’ inject='coldbox:datasource:Abc>

and in the

So what do I need to do to make sure that Wirebox is setup correctly and what else do I need do in wirebox.

dsn = {name=“air40dbadev”, dbType=“oracle”}
to
dsn = {name=“Abc”, dbType=“oracle”}