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

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?

Related

Multiple CLR schemas in Visual Studio SSDT project

I'm trying to have a single sqlproj project in Visual Studio 2022, representing my SQL Server database.
When creating a CLR stored proc or function in C#, the SqlFunction or SqlProcedure attribute has a Name property, but not a schema. It seems the entire project will use the default schema. I'd like to be able to have more than one schema with CLR items.
I've found a couple different ways of moving procs from one schema to another after deployment, but is there any way to get it right in the first place?
For example, by default, if I create a MyProc procedure, I can reference it as dbo.MyProc from a regular proc. But I want that to live in the other schema. Even if I change schemas as a post-deploy step, then my regular procs with EXEC [other].[MyProc] will not compile properly in Visual Studio since it thinks it's referencing a non-existent procedure.
I don't want multiple projects because I want fully-functional schema compare and publish steps for the whole database.

Handling partial database in Visual Studio database project

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.

It is possible to generate SQL script to create only stored procedures for EF mapping?

I have a SQL Server database project with definition of tables, relations, keys, indexes, security, publish profiles, etc. and I also have an ASP.NET Core MVC project.
The issue is that I would like to use Entity Framework for DML operations but the catch is that I am allowed to use only stored procedures (probably from the security perspective, where application account will have only execution permission on those stored procedures and read only on specific tables).
I found that EF can map .SaveChanges() method to stored procedures via model builder like this example
modelBuilder.Entity<SubjectArea>().MapToStoredProcedures();
From the MS docs https://learn.microsoft.com/en-us/ef/ef6/modeling/code-first/fluent/cud-stored-procedures
It can also generate them with migration command. I am not experienced with migrations, but I would like to only generate the SQL for the stored procedures creation and add this script (which was not run yet) into the SQL Server database project (the workaround is to run migration into separate database and generate scripts from the database into the database project, but it seems not nice).
Is it possible to do it somehow?

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

System-Level Custom Views in SQL Server

I would like to do the following in SQL Server (2008 + ):
Define a view, let's call it [MySchema].[MyTableInfo], that queries the SQL Server catalog views, e.g., [sys].[tables], to obtain a customized presentation of the underlying catalog metadata.
Install this view somewhere (in master?) so that it can be called from the context of any database on the server and return the metadata appropriate for that context, just as the catalog views do.
I have seen reference to techniques to do something similar with utility stored procedures, but this is a little different. Is what I'm wanting to do possible? If so, how?
Update:
I found an article that described how to do almost exactly what I want but with stored procedures. The routines are stored in the master database and marked as system objects. When they return metadata from the catalog views/information schema, the do so in the context of the current database.
Using stored procedures to execute these queries would be extremely inconvenient for my use case; is there not a way to mark views and/or table-valued functions as system objects and have them execute in the context of the calling database? I have hacked on this without success...

Resources