Create Database dynamically using asp.net c# code

Santosh0683
Posted by Santosh0683 under ASP.NET category on | Points: 40 | Views : 14948
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();
}
}

Comments or Responses

Posted by: Ervishalm on: 4/6/2015 Level:Starter | Status: [Member] | Points: 10
Hey i m having an error can you please help me..

Login to post response