Going through this right now myself. Looking at your script, does it require that the database connections already be present before looping through the input folder?
It expects the data store items to already exist. You could look into the AddDataStoreItem function, but you'd need the .sde files unless you're going to create them on the fly based on the connection string information within the layer.