Creating datasources with cfadmin in onApplicationStart

Using the current Docker container (Lucee 5.2 application engine running on Apache Tomcat 8 (JRE8))
Trying to create datasources using cfadmin in onApplicationStart

cfadmin(
action = “updateDatasource”
, type = “web”
, password = “”
, bundlename = “mssqljdbc4”
, bundleversion = “6.0.7728.100”
, classname = “com.microsoft.sqlserver.jdbc.SQLServerDriver”
, dsn = dsn
, name = dsn
, newname = dsn
, connectionString = ‘jdbc:sqlserver://’ & databaseServer & ‘;Database=’ & dsn & ‘;sendStringParametersAsUnicode=true;SelectMethod=direct’
, dbusername = “sa”
, dbpassword = “encrypted:”
, connectionLimit = 100
, alwaysSetTimeout = true
, validate = false
, allowed_select = true
, allowed_insert = true
, allowed_update = true
);

I believe the datasources are getting setup but getting the following when trying to actually execute a query
java.lang.NullPointerException at lucee.runtime.db.DatasourceConnectionPool.loadDatasourceConnection(DatasourceConnectionPool.java:136)

Any input or anything else I can provide for help?

Are you able to use the this.datasources[dsn] process/code instead? That’s how we define datasources for most of our Docker containers…

We do have some containers that require datasources set up more traditionally which we use the cfadmin tag during it’s readiness health check that work… Using code like this:

local.settings = {
			"Action": "updateDatasource",
			"Type": "web",
			"Password": Variables.LuceePassword,
			"ClassName": "com.microsoft.jdbc.sqlserver.SQLServerDriver",
			"DNSPrefix": "jdbc:sqlserver://",
			"Port": "1433",
			"Host": local.Host,
			"connectionTimeout": 5,
			"validate": true,
			"storage": false,
			"Clob": true,
			"Allowed_Select": true,
			"Allowed_Insert": true,
			"Allowed_Update": true,
			"Allowed_Delete": true,
			"Name": arguments.Data.Name,
			"newName": arguments.Data.Name,
			"Database": local.DBName,
			"DSN": "jdbc:sqlserver://{host}:{port};DATABASENAME={database};SelectMethod=direct",
			"DBUserName": local.Username,
			"DBPassword": local.Password
		};
		admin attributecollection=local.settings;

Are you able to browse the Lucee admin to ensure that the datasources have actually been created, and can run the verify connections?

HTH

I have what is effectively a master datasource I need setup using the application.cfc pseudo init with environment variables. That needs to be queried to get data to setup all the other datasources. I cant use that master datasource immediately after setting it up in the pseudo init so I was trying to use cfadmin in onApplicationStart.

Not sure of the issue then :frowning:

The pseudo init, i.e. this.datasources should be available to the onApplicationStart() so it should work. Are you able to check they’ve been created, either by viewing the admin or using the cfadmin tag to list the datasource in the onRequestStart()?

I can access the master dsn I created in the pseudo init, but I cant add more datasources to this.datasources from onApplicationStart().

Interesting tho, dumped out the list of datasources and they are all there but the passwords are all different hashes and they should have been the same. Think something is wrong with my arguments. And I would have expected an auth error from the query execute and not a null reference :stuck_out_tongue:

Will poke around that and see whats going on.

Ok, building my master datasource in the application.cfc pseudo init works. But I cant use that master datasource immediately. I tried tapping into cfadmin to build datasources instead. When I list my datasources before doing anything, that master datasource isnt listed. Any datasources I add with cfadmin do get listed but I cant actually use them without getting that null pointer issue. It doesnt give me a non-existant datasource error, just a null reference.

Any ideas why this is?

It’s probably been already fixed, 5.2 is old