String str;
SqlConnection myConn = new SqlConnection("Data Source=localhost;Initial Catalog=Santosh;Integrated Security=True");
str = "CREATE DATABASE MyDatabase ON PRIMARY " +
"(NAME = MyDatabase_Data, " +
"FILENAME = 'C:\\MyDatabaseData.mdf', " +
"SIZE = 3MB, MAXSIZE = 10MB, FILEGROWTH = 10%) " +
"LOG ON (NAME = MyDatabase_Log, " +
"FILENAME = 'C:\\MyDatabaseLog.ldf', " +
"SIZE = 1MB, " +
"MAXSIZE = 5MB, " +
"FILEGROWTH = 10%)";
SqlCommand myCommand = new SqlCommand(str, myConn);
try
{
myConn.Open();
myCommand.ExecuteNonQuery();
Response.Write("DataBase is Created Successfully");
}
catch (System.Exception ex)
{
Label1.Text = "Error occured.
+" + ex.Message.ToString();
}
finally
{
if (myConn.State == ConnectionState.Open)
{
myConn.Close();
}
}