4

I have made a backup of my SQL Azure in a bacpac file and when I try to import the bacpac in localdb it always fail.

Here is the command I use:

PS C:\Program Files (x86)\Microsoft SQL Server\110\DAC\bin> .\SqlPackage.exe /Action:Import 
/SourceFile:"C:\Users\S\Desktop\MyDb.bacpac" 
/TargetConnectionString:"Data Source=(localdb)\v11.0;Initial Catalog=MyDb; Integrated Security=true;"

And here is the error message:

*** Error importing database:Data cannot be imported into target because it 
contains one or more user objects. Import should be performed against a new, empty 
database.
Error SQL0: Data cannot be imported into target because it contains one or more
user objects. Import should be performed against a new, empty database.

My machine is newly installed, and I have never used localdb at all.

2
  • 2
    have you tried different localdb names?
    – swasheck
    Oct 28, 2013 at 14:40
  • Actually, I made it working, I try to repodruce my mistake and will update information here. It was not coming from the name. It seems that VS2013 added the mdf file to the wrong place when I created the database.
    – JuChom
    Oct 28, 2013 at 15:23

2 Answers 2

5

I encountered this problem and, after some frustration, solved it.

What had happened is that you have created, most likely by mistake, a user object in the model Database. On Management Studio look under Databases\System Databases\model. This is the template that is used when you create a new database, and is used when importing the bacpac. If there are objects (such as a table) in the model, they are automatically created at the same time as the new database. The bacpac import then encounters them in what it expects to be a blank database, and so immediately fails.

You'll also see these same objects created if you manually create a new database.

Deleting the object(s) from the model database solves the problem.

2
  • This is the right answer! Kudos to you on discovering that this was the issue. You deserve way more upvotes. Sep 19, 2017 at 8:29
  • And upvotes you shall have, even after 6 years ;-)
    – brijber
    Nov 9, 2022 at 9:33
0

I had the problem on another machine today and solved it like that:

Before doing this make sure to backup all other database

Delete this directory

C:\Users\{your user name}\AppData\Local\Microsoft\Microsoft SQL Server Local DB\Instances\v11.0

Then open a command prompt

cd "C:\Program Files\Microsoft SQL Server\110\Tools\Binn"
sqllocaldb.exe delete v11.0

And after that everything went fine...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.