Visual Studio 2010 Database Project - Unresolved Reference to a Synonym - visual-studio-2010

We have a couple of synonyms that are being used to reference tables in a separate database (that's on the same server).
The actual synonyms are fine, but the stored procs/user defined functions that reference said synonyms show the following error:
Error 13 SQL03006: Column: [dbo].[GetCocosIndexSearched].[User ID] 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: [dbo].[AuditType].[e]::[LOGIN_ID], [dbo].[EMPLOYEES].[e]::[LOGIN_ID], [dbo].[EMPLOYEES].[LOGIN_ID] or [dbo].[SearchCIBirthsRequest].[e]::[LOGIN_ID]. C:\VSTS\Corporate\WARS Audit\MAIN\Source\RBDM.Audit.Database\Schema Objects\Schemas\dbo\Programmability\Functions\GetCocosIndexSearched_1.function.sql 21 5 RBDM.Audit.Database
[dbo].[GetCocosIndexSearched] is a function and [dbo].[EMPLOYEES] is the synonym.
These all work fine in the actual database itself - the problem lies solely with the database project. I've tried adding a reference to the separate database (either through a new database project or a database project schema), but then have conflict issues with the synonym and reference table:
Error 7 SQL04105: The model already has an element that has the same name dbo.EMPLOYEES. C:\VSTS\Corporate\WARS Audit\MAIN\Source\RBDM.Audit.Database\Schema Objects\Schemas\dbo\Synonyms\EMPLOYEES.synonym.sql 2 1 RBDM.Audit.Database
Any ideas? There's a workaround mentioned in another stackoverflow post that talks about placing the creation scripts in Script.PostDeployment.sql - sounds a bit too hacky to me.

This happens because in the caller database you must add a reference to the dependent database and specify also a value for the database name.
Look below:
Then you can create your synonym using the following code:
CREATE SYNONYM [dbo].[mytable] FOR [$(MasterDatabase)].[dbo].[mytable]

Related

How to create a get-graphql-schema enum from Hasura?

I am working on a project which is backed by Hasura. I am having difficulty creating an enum and getting it to auto-generate the values.
I've successfully created a migration according to the enum spec, and verified it is loading values into the database. Next I ran yarn hasura console, and from the console started tracking both tables I created & set BaseColor to be an enum type. I added a permission for public to SELECT from BaseColor.
Next I ran yarn hasura metadata export. That generated a tables.yml with BaseColor's table definition having is_enum true.
Then I ran, yarn update-schema (i.e. get-graphql-schema http://localhost:8080/v1/graphql > schema.graphql). The generated file is missing the BaseColor_enum I would expect to be present for an enum.
get-graphql-schema only generates an _enum for a table if that table is referenced by another.
So, if I add a foreign key that references BaseColor, it will generate BaseColor_enum, otherwise it won't.

Model changed during database created

I have uploaded my MVC3 project , it's s simple blog , at first it works well but after couple hours! following error appears (I've made custom error to Off to see the error)
The model backing the 'SiteContext' context has changed since the database was created. Either manually delete/update the database, or call Database.SetInitializer with an IDatabaseInitializer instance. For example, the DropCreateDatabaseIfModelChanges strategy will automatically delete and recreate the database, and optionally seed it with new data.
to solve this I have to manually delete my database and create again and then restore to the backup that I have created. but after after 2 hours again I get the error!
I really don't have any idea , what caused that ??
When you create a model and ask EF to create a database from it, EF would hash the model and store the hash value with the database. Whenever the context is created, EF recomputes the hash and matches it against what is stored at the database. If the model changes in any way, the resulting hash will be different and EF will throw the exception you have just seen. This is done in order to keep the model in sync with the database.
Is there any way the model could have changed during runtime?
One thing you could do to figure out the difference is to
1.Re-create the database from the model as you are doing now and get it scripted (script1.sql).
2.Wait till the error happens and delete the db and re-create it again and script it (script2.sql)
3.Try to compare the two and see whether you can spot a difference in the schemas.
This should give you an idea of what has changed in the model.
Goodluck

Changed existing entity model and manually updated SQL Server database but still get context changed error

I have an existing MVC3 application and database that is on a SQL Server 2008 R2 and I had to add a bool item to an existing model.
After I added it to the model, I rebuilt and published the project. Then I opened up SQL Server Management Studio and went to the table and added the entry to the column as a bit, I had to make it nullable since the table already contains data.
I thought this would be all that I would need to do to get everything working. However I got this error:
The model backing the 'psllc_DB' context has changed since the database was created. Either manually delete/update the database, or call Database.SetInitializer with an IDatabaseInitializer instance. For example, the DropCreateDatabaseIfModelChanges strategy will automatically delete and recreate the database, and optionally seed it with new data.
I'm not sure what else to do, I went back to the code and changed the bool to bool? so it will be nullable but this didn't help either. I can't drop the entire database since it's full of data, however as a last ditch possibility I could drop this table and re-create it cause it only has a few entries, but I don't know if that will work. I'm not sure what else to do so any advice would be very appreciated.
Update
Since I'm not getting any responses, let me rephrase my question.
How should I update my database (a SQL Express mdf file) to add a bool Column to a Table that has data already? I need the database to match my updated MVC 3 Entity Code First model otherwise I get the above error.
Thanks
Since this is code-first, you should do this code-first: change the class and use EF-migrations to change the database. The way you do it, the model and the database may match, but the meta information in the database is not updated.
By the way, if you supply a default value, you can add a non-nullable column.

Adding columns to DB after publishing using EF CodeF and mvc nugget Scaffold

I have created a web site using mvc 3 and Ef code first , now after publishing the site and it's DB I have found out that I need to add a new columns to one of my DB table,
(the DB already has a lot of data in it )
should I add the columns direct to the DB or should I add to the class?
(just a simple string with get and set)
And how can I do it without losing my data in the DB ?
thanks
Adding the columns to the class should be enough. Evidence you can find here.
Here is the full list of changes that migrations can take care of automatically:
Adding a property or class
Nullable columns will be assigned a value of null for any existing rows of data
Non-Nullable columns will be assigned the CLR default for the given data type for any existing rows of data
Renaming a property or class
See ‘Renaming Properties & Classes’ for the additional steps required here
Renaming an underlying column/table without renaming the property/class
(Using data annotations or the fluent API)
Migrations can automatically detect these renames without additional input
Removing a property
See ‘Automatic Migrations with Data Loss’ section for more information
I suggest you to add the columns direct to the DB and to the class, and test it on the local machine.

Visual Basic 6.0 Code generator

I have a MS Sql 2005 Database , and I want to generate Visual BAsic code of Data Entity Class, I search the web but I can find a tool that I want. If you any information or link please help me.
I've heard that Enterprise Architect has an entity/ORM framework generator for VB6, but I can't say for sure. I suggest you start looking there. reference
I had to roll my own at work, but it's copyrighted by the company so I wouldn't be able to post it here. I can give you a brief synopsis if you want to try it yourself:
I created a "base class" for an entity (VB6 doesn't support inheritance, so this was actually a "wrapped" base class)
Has Methods like Insert, Update, LoadByPrimaryKey, etc.
I created a similar "base class" for a collection of entities.
Supports simple .Where and .OrderBy methods that build a query
I created a code generator that pulled a list of tables from the database
It generates a module for each table with an Enum listing each column name as an ID, and lookup tables to go from column enum to column name, and back
It generates an entity class for each table that wraps the base entity, and has property setters/getters corresponding to each column name
It generates an entity collection class for each table that wraps the base collection class

Resources