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
    have you tried different localdb names? – swasheck Oct 28 '13 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 '13 at 15:23
3

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.

| improve this answer | |
  • This is the right answer! Kudos to you on discovering that this was the issue. You deserve way more upvotes. – Abraham Philip Sep 19 '17 at 8:29
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...

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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