String str;
SqlConnection myConn = new SqlConnection ("Server=localhost;Integrated security=SSPI;database=master");
![](/Images/OutliningIndicators/None.gif)
str = "CREATE DATABASE MyDatabase ON PRIMARY " +
"(NAME = MyDatabase_Data, " +
"FILENAME = 'C:\\MyDatabaseData.mdf', " +
"SIZE = 2MB, MAXSIZE = 10MB, FILEGROWTH = 10%) " +
"LOG ON (NAME = MyDatabase_Log, " +
"FILENAME = 'C:\\MyDatabaseLog.ldf', " +
"SIZE = 1MB, " +
"MAXSIZE = 5MB, " +
"FILEGROWTH = 10%)";
![](/Images/OutliningIndicators/None.gif)
SqlCommand myCommand = new SqlCommand(str, myConn);
try
![](/Images/OutliningIndicators/ExpandedBlockStart.gif) {
myConn.Open();
myCommand.ExecuteNonQuery();
MessageBox.Show("DataBase is Created Successfully", "MyProgram", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (System.Exception ex)
![](/Images/OutliningIndicators/ExpandedBlockStart.gif) {
MessageBox.Show(ex.ToString(), "MyProgram", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
finally
![](/Images/OutliningIndicators/ExpandedBlockStart.gif) {
if (myConn.State == ConnectionState.Open)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
myConn.Close();
}
}
![](/Images/OutliningIndicators/None.gif)
|