<p>How can I create a new database from my C# application?</p>

<p>I'm assuming once I create it, I can simply generate a connection string on the fly and connect to it, and the issue all the  CREATE TABLE statements.</p>

[{'answer_id': 40061, 'author': 'Espo', 'author_id': 2257, 'author_profile': 'https://Stackoverflow.com/users/2257', 'pm_score': 5, 'selected': True, 'text': '<p><a href="http://support.microsoft.com/kb/307283" rel="noreferrer">KB307283</a> explains how to create a database using ADO.NET.</p>\n\n<p>From the article:</p>\n\n<pre><code>String str;\nSqlConnection myConn = new SqlConnection ("Server=localhost;Integrated security=SSPI;database=master");\n\nstr = "CREATE DATABASE MyDatabase ON PRIMARY " +\n    "(NAME = MyDatabase_Data, " +\n    "FILENAME = \'C:\\\\MyDatabaseData.mdf\', " +\n    "SIZE = 2MB, MAXSIZE = 10MB, FILEGROWTH = 10%) " +\n    "LOG ON (NAME = MyDatabase_Log, " +\n    "FILENAME = \'C:\\\\MyDatabaseLog.ldf\', " +\n    "SIZE = 1MB, " +\n    "MAXSIZE = 5MB, " +\n    "FILEGROWTH = 10%)";\n\nSqlCommand myCommand = new SqlCommand(str, myConn);\ntry \n{\n    myConn.Open();\n    myCommand.ExecuteNonQuery();\n    MessageBox.Show("DataBase is Created Successfully", "MyProgram", MessageBoxButtons.OK, MessageBoxIcon.Information);\n}\ncatch (System.Exception ex)\n{\n    MessageBox.Show(ex.ToString(), "MyProgram", MessageBoxButtons.OK, MessageBoxIcon.Information);\n}\nfinally\n{\n    if (myConn.State == ConnectionState.Open)\n    {\n        myConn.Close();\n    }\n}\n</code></pre>\n'}, {'answer_id': 40085, 'author': 'Lulu', 'author_id': 4290, 'author_profile': 'https://Stackoverflow.com/users/4290', 'pm_score': 1, 'selected': False, 'text': '<p>CREATE DATABASE works</p>\n'}]
['https://Stackoverflow.com/questions/40043', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/3314/']