C# Create multiple database programmatically
I followed a tutorial from Mahesh.
I created a windows application with a textbox and a button.
Textbox is used to enter the database name and click on the button to create the database.
The downside of it is that i can only create one database.
I normal code is from sql server the mdf file and the log file I had to enter it hard-coded but like to know how i can use textboxes to make those changes in order to create more than one database.
CreateDatabase = "CREATE DATABASE " + txtDatabase.Text + " ON PRIMARY " +
"(NAME = myDatabaseData," +
" FILENAME = 'C:\\Database\\txtDatabase.Text.mdf', " +
"SIZE = 3MB, MAXSIZE = 10MB, FILEGROWTH = 10%) " +
"LOG ON (NAME = txtDatabase_log, " +
"FILENAME = 'C:\\Database\\txtDatabase.Text.ldf', " +
"SIZE = 1MB, " +
"MAXSIZE = 5MB, " +
"FILEGROWTH = 10%)";
On the form i want to add another textbox for the FILENAME what i have illustrated is not working and not sure how to make it work.
CreateDatabase = "CREATE DATABASE " + txtDatabase.Text + " ON PRIMARY " +
"(NAME = myDatabaseData," +
" FILENAME = 'C:\\Database\\myDatabase.mdf', " +
"SIZE = 3MB, MAXSIZE = 10MB, FILEGROWTH = 10%) " +
"LOG ON (NAME = txtDatabase_log, " +
"FILENAME = 'C:\\Database\\myDatabase.ldf', " +
"SIZE = 1MB, " +
"MAXSIZE = 5MB, " +
"FILEGROWTH = 10%)";
By changing it as illustrated it works but only creates one database.
I want to create more than one database.
the user will be able to enter all the information in the textbox and click on the button to execute the code.
I appreciate for your assistance. Thanks in advance.