I am having trouble getting Visual Studio 2022 (and 2017) to work with a simple Database Project. I have extracted a data tier application and stored it as a .dacpac file. I have added it as a database reference (Same server, different database.)
It is happy with this and can build and deploy it:
CREATE VIEW [dbo].[View1]
AS SELECT * FROM [$(CBS_ODS)].dbo.rm_acct
But this gives errors:
CREATE VIEW [dbo].[View1]
AS SELECT _IsCurrent FROM [$(CBS_ODS)].dbo.rm_acct
Specifically the two errors:
SQL71561: Computed Column: [dbo].[View1].[_IsCurrent] has an unresolved reference to object [$(CBS_ODS)].[dbo].[rm_acct].[_IsCurrent]
SQL71561: View: [dbo].[View1] has an unresolved reference to object [$(CBS_ODS)].[dbo].[rm_acct].[_IsCurrent]
At this point I've come to the conclusion that Database Projects are unusably buggy. Is there (a) any solution to this or (b) any way to turn of parsing/inspection entirely? It seems like the database references can see views, but not the columns in the views?
I think I've found the solution. Basically you need to add the database you're referring to as a reference, as well as all databases that reference refers to! ie. transitive references aren't automatic.
Pretty annoying as it means that the database reference isn't properly encapsulated from the user's point of view.
Related
I am trying to recreate a SQL Server Database project from a live production database in VS2022. I extracted all the different databases from the server as *.dacpac and imported them into VS2022, established the references between them and so on.
Now I've got the problem, that in the life database there are additional Stored procedures and functions in the master, that were added by the developers and are not part of the default masters database that comes with the SQL Server installation.
Thus the references from the databases to these procedures and functions are unresolved, when I reference the System master database. So I created a .dacpac from the live master database and provided it as master reference instead of the system master database. But if I do that, I get other errors:
I have to manually prefix every use of functions or procedures, that are in the master database as master.dbo.some_function instead of simply some_function.
I get errors and warnings for unresolved references to tables like sysobjects and some standard functions and procedures like SP_EXECUTESQL, that are in the master, even if I prefix them:
SQL71502: Procedure: [dbo].[someProcedure] has an unresolved reference to object master.[dbo].[SP_EXECUTESQL]
Number one is annoying but a problem that I can handle, but number two gives me headaches. How do provide references to a master database, that includes both, the user added functions and procedures and the systems default methods and tables? IS there a way to create a .dacpac including the System databases?
I have a Visual Studio database project which I cannot build because of many SQL71501 errors.
Error SQL71501: Computed Column: xxxxx contains an unresolved reference to an object.
Either the object does not exist or the reference is ambiguous because it could refer to any of the following objects.
The reason for the errors is that I have created a View which references an external table. The external table cannot be added into Visual Studio either as code, or as a reference. These external data sources and external tables are handled by a different process when the database is created. Plus, the external tables and external data source have variable names based on the environment which makes adding them into VS impossible. Technically they could be added as dynamic SQL, but then this breaks the security model, which is a different story :(
If it would simply ignore these errors, build and deploy, everything would be okay. But even though I have told Visual Studio to ignore these, it doesn't appear to have any affect.
How can I suppress these errors and force a build?
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
I am using Visual Studio enterprise 2017 (Version:15.71.1) and SSDT(Version:15.1.61804.210)
and also using TFS to keep my code. In my database project all tables are temporal table.
Now when i am changing column type or column name in TFS , i am not able to build my project so not able to generate publish script.
I am getting error :
Error SQL71609: System-versioned current and history tables do not have matching schemas. Mismatched column:"XXXXX"
Do we have any solution for this ?
Generally you can try explicitly defining the history table, then manually keep the schema of the current and history table in sync.
Reference this thread: Avoid schema mismatch in System-Versioned tables
UPDATE:
As you mentioned the solution which worked for you is to make these changes in SQL Server Object Explorer (You can see it by right clicking on DB project and choosing the “View in Object Explorer” option). You need to do the modification here and just save it and it will work.
The solution which worked for me , is to make these changes in SQL Server Object Explorer (You can see it by right clicking on DB project and choosing the “View in Object Explorer” option). You need to do the modification here and just save it and it will work.
I am using Visual Studio 2008 Database Project GDR2 to manage multiple databases and I am getting a number of errors related to synonyms.
Project-A has a reference to Project-B because Project-A has a number of synonyms to tables in Project-B. The full error I'm getting is "TSD04105: The model already has an element that has the same name dbo.[OBJECT]". This always points at the synonym.
The issue seems to be that the synonym on Project-A has the same name as the table on Project-B. Obviously I could rename all my synonyms so that they have different names than the tables, but this introduces a LOT of work on my part (there's over 140 synonyms so far).
Removing the reference to Project-B will get rid of that error, but instead all of my stored procedures in Project-A generate errors because it can't reference the tables in Project-B any more.
Is there a way to fix this problem short of renaming all the synonyms? What is the appropriate way to handle this situation in the Database Project?
I had this issue between a 2008 server project and a database project and I solved it by using a literal Database Variable Value.
Referencing project properties -> References Tab -> Database Variable Value
I would say that you could also use a Database Variable Name/Value pair as well.
At my previous employer we prefaced each item with item type.
syn_BeerName
vw_BeerName
tblBeerName
Usually, synonym to view, view to table.