Exemplo n.º 1
0
        public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Function, "post", Route = "database")] HttpRequestMessage req, TraceWriter log)
        {
            log.Info("CreateDatabase processed a request.");

            HttpResponseMessage rtnResponse = null;
            string workspacename            = string.Empty;

            try
            {
                // Get request body
                AddDatabaseRequest requestparameters = await req.Content.ReadAsAsync <AddDatabaseRequest>();

                SQLHelper.CreateCustomerDB(requestparameters);

                SQLHelper.CreateCustomerDBSchema(requestparameters);

                rtnResponse = req.CreateResponse(HttpStatusCode.OK);
            }
            catch (AggregateException ex)
            {
                rtnResponse = req.CreateResponse(HttpStatusCode.BadRequest, ex.InnerException.Message);
            }

            return(rtnResponse);
        }
Exemplo n.º 2
0
        public static void CreateCustomerDB(AddDatabaseRequest requestParams)
        {
            using (SqlConnection connection = CreateSQLConnection(requestParams.server, "master", requestParams.credentials))
            {
                connection.Open();

                // create database
                SqlCommand cmd = new SqlCommand($"CREATE DATABASE [{requestParams.database}]", connection)
                {
                    CommandTimeout = 60 // default is only 30, if working with Azure SQL DB, we need to bump this up
                };
                cmd.ExecuteNonQueryAsync().Wait();

                connection.Close();
            }
        }
Exemplo n.º 3
0
        public static void CreateCustomerDBSchema(AddDatabaseRequest requestParams)
        {
            // create table in database
            using (SqlConnection connection = CreateSQLConnection(requestParams.server, requestParams.database, requestParams.credentials))
            {
                connection.Open();

                SqlCommand cmd = new SqlCommand(createTable, connection)
                {
                    CommandTimeout = 60, // default is only 30, if working with Azure SQL DB, we need to bump this up
                    CommandType    = CommandType.Text
                };
                cmd.ExecuteNonQueryAsync().Wait();

                connection.Close();
            }
        }