2

I was always able to restore a bacpac to a SQL Server in Azure using a local file like this:

ds = new DacServices(connectionString);         
ds.ImportBacpac(BacPackage.Load(filePath), dbTargetName, 
                new DacImportOptions { 
                    ...
                    }
                });

Then I looked for a way to not fully load the bacpac to the memory, so I discovered that BacPackage.Load has a 2nd argument that supposed to take care just for that so I used it like this:

BacPackage.Load(filePath, DacSchemaModelStorageType.File)

When I added that usage of the 2nd parameter, I started getting an exception when trying to restore the bacpac:

Error restoring data base to server: .NET Core should not be using a file backed model

Why can't I use it like that? I don't want to load the bacpac to the memory, so what can I do?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
CodeMonkey
  • 11,196
  • 30
  • 112
  • 203
  • It's a bug: https://github.com/microsoft/azuredatastudio/issues/12730 – Martin Costello Feb 28 '21 at 13:46
  • Is your database mounted on a SQL Server or are you just reading directly from the MDF file. It looks like you are using Entity and the database is mounted on a Server. So the only memory you are using is based on the Select statement which loads only the items in the Select into your model. So adding a Where to the select will limit the amount of the database that gets loaded into your model. If your data has a DateTime you can limit the amount of data that gets loaded by the Date. – jdweng Feb 28 '21 at 13:47
  • @MartinCostello this bug there seems like a build error? while mine is a runtime error – CodeMonkey Feb 28 '21 at 13:52
  • @jdweng we're talking here about restoring a full database from an already made bacpac file. I can't control its creation itself - I get an already made one – CodeMonkey Feb 28 '21 at 13:56
  • Instead of moving entire database in one chunk (one bacpac) do it in pieces. See : https://learn.microsoft.com/en-us/archive/blogs/sqlcat/migrating-from-sql-server-to-azure-sql-database-using-bacpac-files – jdweng Feb 28 '21 at 14:06
  • @jdweng could you please point me to the right place in the link? I can't seem to find somewhere there that describes how can you divide a bacpac into pieces. What i did manage to read is that they are talking about uploading the bacpac to azure as a blob, while I'm importing it locally from my machine – CodeMonkey Feb 28 '21 at 14:57
  • If yoi uhave multiple tables you can move one table at a time. Each table you can use a WHERE ot divide into pieces. – jdweng Feb 28 '21 at 19:26
  • @jdweng i have only a given bacpac file with no information what's in it. – CodeMonkey Feb 28 '21 at 22:13
  • It is a zip file with an extension bacpak. You can open with ZIP tool. You may need to rename file to open. – jdweng Mar 01 '21 at 00:34
  • @jdweng We are talking about doing it with a C# code, not manually – CodeMonkey Mar 01 '21 at 07:06
  • You can rename a file in c#. Also there is unzip libraries in c#,. – jdweng Mar 01 '21 at 09:07
  • do you have a code example that showing how I can send one table at a time and how then I can make the actual import in Azure with all these tables? – CodeMonkey Mar 02 '21 at 13:21

1 Answers1

0

The second parameter is optional

Just do:

BacPackage.Load(filePath)

When I added the second parameter, I had the same issue, when removed it worked fine.

Yogurtu
  • 2,656
  • 3
  • 23
  • 23