Thursday, 1 February 2018

Dynamically Creating Database Using C# Asp.net Code.

public ActionResult restoreazuredata()
        {
            string dbName = Txtdbnmae.Text;
            string backup = @"CREATE DATABASE [" + dbName + "] AS COPY OF [SatyaMetaData]";// SatyaMetaData Means Exiting Database
            SqlConnection myConn = new SqlConnection("data source=tcp:satya.database.windows.net,1445;persist security info=True;user id=satyauser;password=satyas46;database=master");//Your Connection Connection String

            try
            {
                SqlCommand cmd = new SqlCommand(backup, myConn);
                myConn.Open();
                cmd.CommandTimeout = 10000;
                cmd.ExecuteNonQuery();
                myConn.Close();
                return Json("1");
            }
            catch
            {
                return Json("0");
            }

        }

No comments:

Post a Comment