1

I have a bacpac file and I need to import bacpac to a dataset type variable.

I have checked QL Azure BACPAC extraction, however I do not know how to use ImportBacpac command from DacServices:

SqlConnectionStringBuilder csb = new SqlConnectionStringBuilder();
//csb.DataSource = "servername";
//csb.Password = "whatever";
//csb.UserID = "whatever";

DacServices ds = new DacServices(csb.ConnectionString);
ds.ImportBacpac()

There is no example in MSDN website for ImportBacpac DacServices.ImportBacpac Method

Then I discover another post How to import Azure SQL backup (.bacpac) to LocalDB using Visual Studio? The method in that post uses a command line involving SqlPackage.exe

How do I import/read that bacpac to Dataset using that command line method above in C#? Or have I missed something?

Thank you.

Community
  • 1
  • 1
hunterex
  • 565
  • 11
  • 27

1 Answers1

2

So, I also had this problem, but I just solved it. You have to send sourcefile using BacPackage.Load() My example:

var ds = new DacServices(Csb.ConnectionString);
ds.ImportBacpac(BacPackage.Load(Path.Combine(directory + lastBacpacBackup.Name)),"DB_NAME", new DacImportOptions());

Remember, you can't keep database with the same database name as you want to create.

  • "you can't keep database with the same as you want to create" Looks like you are missing a word here. Same as what? –  Aug 15 '17 at 16:13
  • Maybe you can answer this one as well: https://stackoverflow.com/questions/66311105/creating-azure-db-with-huge-backpac-files – CodeMonkey Feb 22 '21 at 08:54