create database in Advanced Query

create database in Advanced Query


i use a sql server 2008 and want to create a databse with Advanced Query. My sql look like:
Without the Commit Transaction command, the following error is thrown: "CREATE DATABASE statement not allowed within multi-statement transaction.". My Problem ist that the database is created, but an other error is thrown: "Value cannot be NULL. Parameter name: key". what am I doing wrong?

Any help appreciated.

Hi arne,

Couple issues there.
  1. Advanded Queries are prepared to have be SQL queries, not DDL statements.
  2. For security reasons the runtime user (and looks like your's have) used on the platform should not have permissions to create or alter things on your database. Creating databases, even less.
  3. "COMMIT TANSACTION" statement messes up internally the .net Connection/Transaction variables. You can try using just "COMMIT" ...but then again, its not recommended to use operations like that inside advanced queries, since they are not "queries". The platform expects to be able to manage the transactions, the the commit/rollbacks inside advanced queries can be unexpected and will cause problems if the transaction is released.

Why do you need to create databases at runtime?

João Rosado
Hi João,

the user has the permissions. he is admin. With the "COMMIT" statement, the same error is thrown. we need this for multi-tenant. every tenant has a seperate database. to create a new tenant we need a new database. so it is not pissible to create a databse within the agile plattform?

Hi Arne,

The OutSystems Platform deals with almost all those low level details when implementing applications with multi-tenancy capabilities.
This means that you don't have to create separate tables per tenant and manage the mapping between tables and tenants.

I would suggest that you took some time to read the following documentation: Hope this helps you get started.
HI Joao,

i know this features. but the multi-tenant feature in the agile plattform only works with internal entities, not with external databse (use sql server).