I have created a new Azure SQL Database using the "Import Database" option in the Azure SQL Server. And of course, used a bacpac of another Azure SQL Database.
Now, I want to update this newly created database using the updated bacpac again. But it looks like there is no option in either SQL Database or SQL Server resources. Any idea how this can be achieved?
Tried the "Import database" option in the Azure SQL Server and but that will only create a new database.
No, it is not possible to restore a bacpac file to an existing Azure SQL database. A bacpac file is a data-tier application package that contains the schema and data of a SQL Azure database.
For the reason explained above you can restore a bacpac on an existing database if the database is empty only.
byte[] bacpac = File.ReadAllBytes(@"<local_bacpac_filepath>");
// restore what we have on production
using (MemoryStream ms = new MemoryStream(bacpac))
{
BacPackage package = BacPackage.Load(ms);
DacServices services = new DacServices("<connection_string>");
services.ImportBacpac(package, "<existing_database_name>");
}
If you want to overwrite an existing database with the data from a bacpac file, you have to first delete the existing database and then import the bacpac file with the same name as the deleted database.