Handling partial database in Visual Studio database project - sql-server

So we have a SQL Server database that is replicated from a 3rd party vendor's cloud down to our local database. Data in the tables is replicated down continuously from their cloud servers and occasionally they update the full database with new changes to structure. Their schema is the default dbo schema.
For reporting, we've added a second schema (let's call it abc) where we add some additional tables as well as some functions/stored procedures that reference the data in both the abc and dbo schemas. I have set up our abc schema in Visual Studio as a database project and it looks great, however, I can't deploy/publish anything because when it builds, it says it can't find tables that are in the dbo schema. Obviously that's just because we haven't created them in our database project because we've only setup the scripts for our abc schema.
Is there a way to tell Visual Studio to either ignore those errors or to look in the actual database (not the database project) for those tables?

You should be able to create a dacpac of the "base" database, then include that as a database reference using "same database, same server"? That would keep the objects out of your project, but allow you to reference them in your code.

Related

How to migrate the schema of a SQL Server database from on-premise to SQL Server on AWS RDS with non-supported features

I'm working on taking a on-premise server that works with SQL Server 2019 and migrating this to the cloud. The data right now is not the important thing, but rather the schema since this is a proof of concept. The main issue is that the on-premise server uses filestream to sometimes handle files. This will have to change in the future as refactoring and application updates take place.
The easiest way I thought would be to generate a schema .sql script from the old db and run that in the new environment, but this generated a TON of errors (25k).
Most of the errors include:
Failed permissions in database 'master'
Not finding certain objects in the new clean DB
Extended properties are not permitted on an object or it doesn't exist
Invalid data types
Database doesn't exist or permission not allowed
Filestream feature is disabled
So this probably won't work as a drop in solution to get the schema migrated to the new db. I've heard about AWS DMS (data migration service), but I don't know a lot about this. I'm asking, what tools could I look into to migrate over to RDS when RDS doesn't support features native to SQL Server?
One way to import schema is through the generated scripts wizard. You will have to manually tweak some things to make filestream and the local configuration of the sql server work nicely with aws RDS.
Generate and Publish Scripts Guide
Go to the source database
Right click the database in the menu on
the left (Object Explorer) Tasks>Generate Scripts
Select All tables,
procedures, etc.. except for filestream tables.
In the Scripts wizard pop up under Set Scripting Options, choose to make a .sql file, under advanced options, choose Schema Only. This will generate a script with only meta data for the tables and not the data in them
Generate the file.
Copy the .sql file over to the
EC2 instance (probably the Bastion Host) that is connected to the
RDS instance.
Open MS SQL Management Studio and right click on the
top most object in the Object Explorer and open a new query.
Copy and paste the code inside the .sql file into the query window.
Change the file path location of the data and log file to be
D:\rdsdbdata\DATA\TEST_AWS.mdf and D:\rdsdbdata\DATA\TEST_AWS_Log.ldf 
respectively. Any other file location will not be recognized by RDS
and will fail to create the table.
Comment or remove the lines of code that include:
a. ALTER DATABASE [TEST_AWS] SET TRUSTWORTHY OFF  
b. ALTER DATABASE [TEST_AWS] SET HONOR_BROKER_PRIORITY 
c. ALTER DATABASE [TEST_AWS] SET DB_CHAINING OFF Creating global users
d. FileStream
Execute the Script
Consider adding towards the top of the script DROP DATABASE [TEST_AWS] before the creation of the new database just in case you need to run the script multiple times to find the errors. This will save you from overwriting errors or having a unfinished table in memory.

SSDT SQL Server Data Tools Customer specific requirements

We are using SQL Server Data Tools (SSDT) to manage our customer databases.
In theory all databases are identical, but in practice we have a few stored procedures (and one trigger) that would change from one customer to another.
We created a main SSDT for everything common, and then one SSDT per customer containing only the specific stored procedures (no tables).
In the specific SSDTs we get warnings because SSDT can't find the tables referred in the stored procedures, but we can live with that (obviously SSDT won't be able to validate the table's fields since it can't find the table). For the trigger, we get an error (table can't be found), thus the database project doesn't compile.
How should we manage that? I guess we should not be alone in this situation.
Is there a way for a database project to refer objects (tables) from another database project ?
Thanks,
Yves Forget
Daniel N gave the right direction, I'll just explain. Let's say you have database project named DatabaseA which will contain the only objects that 100% match for every customer. Then you create another database project DatabaseB and include DatabaseA as "the same instance, the same database". In database DatabaseB you can add customer specific objects. Then you can create other database for other customer in a similar way.
IN SSDT you can add another database project or dacpac as a reference.
In the properties for the referenced project you will be able to set where the referenced database resides, same server same database, same server diff database etc
https://msdn.microsoft.com/en-us/library/jj684584%28v=vs.103%29.aspx?f=255&MSPPError=-2147217396

How can two SQL databases be merged into one database?

I have 2 SQL Server databases. The reason is because I created an ASP.NET MVC project using "Individual User Accounts" for authentication. This created a default connection with a database that includes the following tables:
AspNetUserClaims, AspNetUserLogins, AspNetUsers, _MigrationHistory
I then went a step further and built out my own custom roles with a RoleController. So I also have a table for AspNetRoles and AspNetUserRoles. Everything with this is working.
I also have another database that I built in Management Studio that is holding all of the data of my application. I am using Entity Framework to communicate with the database.
I currently reference both databases in my web.config connection strings.
But I would like to migrate the database from the default connection (with my AspNetUsers) into the one in Management Studio.
Is it as simple as copying the tables and putting them in my other database in Management Studio or can I copy the whole schema? Just trying to figure out the best approach here.
You can migrate tables from a database to a diferent one. On SSMS, just right click on a database, select Tasks -> Generate Scripts, and use the wizard to create a script with the table definition and data (optional) to be executed on the new database.

Visual Studio - Configure Data Source - Non-dbo Schema Stored Procedure

I work for a large company with big data and we have a data architecture where we mostly use non-dbo schemas. When I use Visual Studio (2013 Ultimate) and the Configure Data Source feature, it only lists stored procedures in the dbo schema. The ones I need are located in other schemas (rpt., adm., usr., etc.). Is there a configuration setting or some other way to get access to non-dbo resources?

SSDT Schema Compare Update Removes schema from objects

When using the Schema Compare tool with SSDT in Visual Studio 2012 to update a database project with changes made to schema objects on a local database, the schema is 'lost' from the object declaration. I am connected to my local sql server instance using a Windows account and this account has default schema of dbo on the database being compared.
For example, a local stored procedure definition may be:
CREATE PROCEDURE [dbo].[SetPriceBounds]
But when this is added to the database project using schema compare, it becomes:
CREATE PROCEDURE SetPriceBounds
When this is subsequently deployed to another SQL Server instance, it fails with the error:
The default schema does not exist.
I need to get the dbo. prefix preserved when the schema comparison is executed, any ideas are welcome.
This has been solved by setting the default schema on the deployment target database to dbo for the user that was performing the deployment. I'm not convinced this is the right way to fix the problem, but it works.

Resources