Hello!
I am trying to create a database programmatically with the following code:
@Select = @Select + sql;
String str;
SqlConnection myConn = new SqlConnection(<a valid="" connection="" string="">);
str = "CREATE DATABASE " + sql + " ON PRIMARY " +
"(NAME = " + sql + ", " +
"FILENAME = '" + @Select + ".mdf', " +
"SIZE = 2MB, MAXSIZE = 10MB, FILEGROWTH = 10%) " +
"LOG ON (NAME = " + sql + "_Log, " +
"FILENAME = '" + @Select + ".ldf', " +
"SIZE = 1MB, " +
"MAXSIZE = 5MB, " +
"FILEGROWTH = 10%)";
where the variable sql is a valid database name ("ChaosSpaceMarines").
@Select is a valid path ("E:\\databases\\")
This code works fine once. But if I delete the database ChaosSpaceMarines (and all associated files) I get the SQL error "Database ChaosSpaceMarines" already exists. Even if I create the new database on a different drive. (Also tried a different directory).
Can anybody tell me why I can only create the named database only once? The database contains 22 tables and currently I am trying to debug the SQL statements that create the tables. It is a pain to have to use a different table name each time I restart the program.