Search code examples
c#sqlsql-serverdatabaseprogrammatically-created

Secure way of creating SQL Database based on user input in C# app


I am struggling to find the solution myself on the Internet.

I have recently learnt that @parameters cannot be used to represent Database Names.

In my case each user should depend on the designated database(for numerous reasons). I thought of creating the database using sqlCommand that combines sql command and input string dynamically but was told that is a silly idea(I agree).

I've heard of SMO, although not sure if this will put me into the right place.

Maybe there is a way of generating random name for database when prompted by user, and then store that name in 'master' database's table along with username for identification purposes?

Until I find the right solution I'm pretty much put on hold with work.


Solution

  • I built an app that did something similar to this and what I did was kept a blank database on the SQL Server and made a stored procedure to copy it (with a different name of course).

    There are plenty of use cases for single database per user despite what the trolls say.