How to extract MSSQLServer database as .dacpac without VerifyExtraction? - sql-server

I want to extract a database schema of a MSSQLServer database with Server Management Studio. I use the Extract command "Extract Data-tier Application.."
In the database are several references to another database. Because of this I get the following error.
Error extracting database: Validation of the schema model for data package failed.
Error SQL71562: Error validating element [dbo].[x] has an unresolved reference to object [dbo].[y]. External references are not supported when creating a package from this platform.
The problem is, that SSMS uses the SQLPackage.exe with parameter /p:VerifyExtraction=True. When I use the console and call SQLPackage.exe without this Parameter, it uses /p:VerifyExtraction=False by default and I can create the .dacpac file.
Is there a way to configure SSMS to disable verification?

I wasn't able to find a method that works in SSMS (2008 R2 or 2012), either, but Visual Studio (2013) with SSDT seems to work: Within VS, go to SQL Server Object Explorer, connect to the server in question, right click the database in question, Extract Data-tier Application, and then adjust the Extract Settings, one of which is "Verify extraction". I don't know why MS doesn't just build that into SSMS.
One somewhat-odd thing I noticed from doing, this, though, is that VS will only extract a .DacPac via this method. Even when you choose to add data to the extract, the extension is still .DacPac. I was under the impression that .DacPacs were solely for Schema Only, while .BacPacs were for Schema + Data. Regardless, after VS created the .DacPac (Schema + Data) file, SSMS was able to import it fine using "Deploy Data-tier Application..." wizard.

If you cannot use Visual Studio you can use the command line SqlPackage application to extract the schema from the database. By default, this does not verify the schema (no, I don't know why SSMS and the command line offering have different defaults!). SqlPackage.exe can be found in C:\Program Files (x86)\Microsoft SQL Server\<SQL_VERSION>\DAC\bin.
For example, the following extracts the schema for MyDatabase from the local SQL Server instance and outputs it to a .dacpac file on the local filesystem:
sqlpackage /Action:Extract /SourceDatabaseName:"MyDatabase" /SourceServerName:localhost /TargetFile:"C:\SomeDirectory\MyDatabase.dacpac"
If you want to include schema verification at a later stage, you can set the flag explicitly by adding /p:VerifyExtraction=True to the command line.
Full information on SqlPackage.exe can be found here:
https://msdn.microsoft.com/library/hh550080.aspx

Related

SQL backup file made with MSSMS is not working... on MSSMS (Microsoft SQL Server Management Studio)

I Generated an SQL File to backup a database using MSSMS:
Right click on database
Generate scripts
Marked "Schema and data" on "Types of data to script"
As a result I got a complete SQL that effectively seems to contain all the needed information to rebuild my db from scratch, data included.
To test it, I tried to run it locally, and found myself stuck because MSSMS is throwing errors on the SQL Script that it itself made.... I does not make any sense :(
Am I missing sth?:
This is the first lines of the sql file just as MSSMS made it:
Any ideas?
EDIT 1
This is the error I get after removing all "ALTER DATABASE" (I assumed those were the configuration specifications that were causing trouble)
It now says the tables are already created though they are not present in the database (it did create the database tough, It's a progress!)
The script you are trying to execute contains elements that are not valid because the edition of SQL you are running locally is not the same as the edition of SQL used to generate the script.
In your case, the script was generated from azure SQL, but you are running it on sql server express edition (localdb)
Remove the azure SQL specific elements and it will work.
The default scripting option in SSMS object explorer is the same database engine type and edition as the source database. It seems the source database is Azure SQL Database based on the CREATE DATABASE syntax so the script will not run against a stand-alone instance like your LocalDB instance.
You can either modify the script or generate a new script appropriate for your target instance. To generate a script for SQL Express LocalDB, click on the Advanced button on the Set Scripting Options page of the Generate Scripts wizard. Select these options:
Script for the database engine edition: Microsoft SQL Server Express Edition
Script for the database engine type: Stand-alone instance

SQL Server Restore BACPAC throws error on a missing User-defined table type

I've exported an Azure SQL Database using the Azure Portal into a .bacpac file.
Using SQL Server Management Studio 17.9.1, I run the "import data-tier application" wizard and select the .bacpac file. It won't import successfully:
One error message states:
So it looks like he is complaining that the "IntegerIdList" User-defined Table Type is not present (or he can't find it). But it is available in the source database:
Is there a way to import this bacpac file into an existing database? That way I can create this Table Type before I run this wizard.
To my knowledge, there is no way to restore a bacpac to an existing database.
Try to install the latest version of SQL Server Management Studio (18.1 at this moment) and try again.
If the latest version of SSMS does not solve the issue, as a workaround copy the database with another name, script the user-defined table types (UDTT) and all dependent stored procedures, remove them from the newly created database and export this database instead of the original database. Restore the bacpac on your existing SQL Server and when the restore has finished, run the script that will create the UDTT and all dependent stored procedures.
UDTTs are supported on SQL Server 2008 and later only.

Copy a database schema into another database in SQL Server using VB.NET

Using SQL Server 2014.
I want to copy a database (say d1) schema (without data) to another database (say d2) using vb.net.
Such that on a click of a button, the database is created/copied.
Searched many things, but not helpful.
Searched Microsoft TechNet Library, followed every step from the link but something not working...
How to: Transfer Schema and Data from One Database to Another in Visual Basic .NET
Database is been copied but tables/procedures/views nothing inside.
Missing type means you have not added all possible references. You even mention further below in your post that a dll is not available anywhere, so how can you have added all possible references?
So, searching for "smoenum.dll" on google, finds this link: https://social.msdn.microsoft.com/Forums/sqlserver/en-US/252adaa4-fc12-436d-91df-a2e8a98c7f2f/sql-2008-missing-microsoftsqlserversmoenumdll?forum=sqltools , which mentions that the the file has been renamed in later versions of SQL Server:
"Microsoft.SqlServer.SmoEnum.dll is available in SQL Server 2005 and
is removed from SQL Server 2008. If you have a SQL Server 2005
installed in any machine, it would be under C:\Program Files\Microsoft
SQL Server\90\SDK\Assemblies folder But the dll wont be available in
the C:\Program Files\Microsoft SQL Server\100\SDK\Assemblies
directory."
Instead you should use:
"Microsoft.SqlServer.SmoExtended.dll
Microsoft.SqlServer.Management.Sdk.Sfc.dll
Above dlls are newly added in SQL Server 2008 which might be useful
for your case.
The other dlls useful for your case in both versions are
Microsoft.SqlServer.Smo.dll Microsoft.SqlServer.SqlEnum.dll"

Sql dacpacs exporting data

From my understanding when extracting a sql database as a dacpac it includes the data structure with views/procs etc but no data.
a bacpac includes the structure and data but cannot be upgraded.
I read some where that dacpacs can include data now but I cannot find anywhere that shows how to do that. Is this possible?
Yes, it is possible! Easy way to include data in DACPAC is to use SQL Server Database project in Visual Studio:
Add data to post-deployment script (INSERT command etc.).
Build the project - it gaves you a DACPAC file.
Go to SQL Server Management Studio.
Execute Databases -> Deploy Data-tier application command:
Now you have a new database with data from a single DACPAC file!

how to resolve dependency when comparing schema in TFS for SQL Server project or when creating .DACPAC files in SSMS?

I have SQL server project setup in TFS. when i am trying to compare schema from source control project with Target project, i am getting some error on Unresolved reference. so i tried to add database reference from using "Add Database Reference" dialog box and it is asking me to add .DACPAC file.
to create .DACPAC file i went in SSMS and right clicked on DB and selected Tasks->Extract Data-tier Application option. it is getting failed because it can not resolve dependency for some of database objects (which uses linked server connection). so my question is how can i resolve this dependency so that i can add .DACPAC file in TFS to compare schema and generate scripts for deployment from TFS. i am using Visual Studio 2013.
Thanks for your help.
The correct way to handle it would be to also create a dacpac for the database the other end of the linked server and add a database reference as "Other Server, Other Database".
Instead of SSMS I would create a new ssdt project in ssdt and import each database as it will be more reliable than the ssms extract.
Ed

Resources