VS2010 - SQL CRL Deploy error - Deploy error SQL04105: The model already has an element that has the same name - visual-studio-2010

I have a SQL CLR project created in VS2010. It needs to run PreDeployScript.sql and PostDeployScript.sql. Both files exist in project. However, when trying to run the deploy, I get the following error messages:
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\TeamData\Microsoft.Data.Schema.SqlClr.targets(96,5): Deploy error SQL04105: The model already has an element that has the same name dbo.PropertySetCollection.
This message is repeated for every single type we have. This leads me to believe that PreDeployScript.sql was not run.
Has anybody else run into this issue? Is there a workaround?

Make sure you have not changed the Solution name. If you have you will now be out of sync with the assembly name on the SQL Server. To fix this just drop all the stored procedures for the existing assembly, drop the assembly, then try the deploy again. A new assembly will be created on SQL Server with the Solution name that is in VS.

Try using the Sql Proviler to check if the PreDeploy.sql has run.
Also read this:
https://connect.microsoft.com/VisualStudio/feedback/details/539211/db-projects-with-same-object-names-cannot-be-used-as-database-reference-error-sql04105?wa=wsignin1.0

It is a bug in VS2010 SQL CLR deployment. It has do to with dropping / adding computed columns in pre/post deploy scripts. MS is working on a solution.

Related

Creating a Windows forms app with database

I am using 2010 ultimate and just build a simple windows forms application. Just added a database as well to the form. Pull the application file out of bin directory. Tried to run but got error as unable to attach database? Installed Microsoft SQL Server Compact 4.0 and got same error? What am i dong wrong?
Error:
An attempt to attach an auto-named database for file C;\Users\Admin\Desktop\Database1.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share
Use C:\Users\Admin\Desktop\Database1.mdf instead of C;\Users\Admin\Desktop\Database1.mdf
The reason i am getting a error is because i was trying to run the app file without the database in the same folder, in this case the desktop. I am currently trying to rectify this. I think i will go with a ado.net entity database online and forget integrating a local database with the desktop application. –

TSD00563 Deployment may encounter errors because it depends on [sys].[sp_executesql] and it does not exist in the target database

I'm running into a very annoying issue. One of our SPROC is building up a dynamic bit of SQL which is then executed with sp_executesql (please let's not go into the issues with building up SQL strings for execution).
Using Visual Studio 2010 Database Project (aka. DataDude) to to schema comparisons and deployments and I'm getting the error below for the SPROC:
TSD00563 This deployment may encounter errors during execution because [dbo].[MYSPROC] depends on [sys].[sp_executesql] and [sys].[sp_executesql] does not exist in the target database
Does anyone know how I can get around this?
I have a reference to the master database schema file, but it makes no difference. Also, it's not referencing master, but sys instead.
Many thanks,
Jaans
"The issue you mentioned is a known issue, we had fixed this for RTM. And when you add a db reference to master .dbschema file, you need to make sure the database name part is choosed as literal and named "master""
http://social.msdn.microsoft.com/Forums/en-US/vstsdb/thread/68b0ce97-5275-42af-b213-bd456ce882d7
Use a . prefix before the [sys].[sp_executesql]
Here's an example
EXEC .sys.sp_executesql 'SELECT * FROM Table'
Strange indeed!

VS 2010 Database Project bug?

I am having a very weird problem with building a SQL Server 2008 Database Project from within Visual Studio 2010. I created the database project and then imported the database objects and settings from a local database that I am working with. I then went to build the database project and got the following error:
SQL03006: View: [dbo].[GovCAStaff] has an unresolved reference to object [CTS_Staff].[dbo].[Client_Assignments].
The problem appears to be that the view GovCAStaff is referencing a table in a different database (CTS_Staff). However, I have numerous functions and stored procedures in the same database project that are referencing tables in a different database but the build process only generates warnings for those, not errors. Other than rewriting the view as a function, does anyone know of a way to get rid of this build error? Is this a known limitation of views within database projects? Anyway, I am really stumped. Have googled this topic and haven't found anything relevant. Any help would be greatly appreciated. Thanks in advance.
The reason this error shows up in views, but not functions and stored procedures, is because that is how SQL Server itself will react if the database/table does not actually exist. In other words, in SQL Server you can define stored procedures and functions that reference tables that don't exist or are otherwise inaccessible. Not so for views.
The way to resolve this issue is to add a 'database reference' (a .dbschema file) to your project so that the project build process knows about the schema of that other database. Where to get this magical .dbschema file?
Create another database project (presumably in the same solution) for the other database. This is most convenient, as you can just create a 'project reference' and everything stays up-to-date (you wanted a DB project for that other database, anyway, right?).
Create the .dbschema file manually via vsdbcmd.
If the database is a 'system' database (e.g. 'master' or 'msdb'), you can use one of the pre-built .dbschema files ({Program Files}\Microsoft Visual Studio 9.0\VSTSDB\Extensions\SqlServer{version}\DBSchemas).

The model already has an element that has the same name

I just created a new solution made up of two projects:
SQL Server 2008 Server Project
SQL Server 2008 Database Project
The Database Project has a Database Reference to the Server Project. When I try to build the solution I get three errors:
Error 291 SQL04105: The model already has an element that has the same name
dbo.sp_scramble
Error 292 SQL04105: The model already has an element that has the same name
dbo.sp_scramble.#Table.
Error 293 SQL04105: The model already has an element that has the same name
dbo.sp_scramble.#Field.
Both the Server and Database project were created by using the "Importing Objects and Settings..." option.
Also, the Server Project alone, builds without errors.
I'm using the project templates that shipped with VS 2010.
I guess my question is what caused these errors?
UPDATE: I fixed the errors by renaming the stored procedure, still I wonder what caused the error.
I fixed the errors by renaming the stored procedure.

How do you fix TSD02016 error in Database

I have a database I am using the Visual Studio 2010 Database Project tool vsdbcmd.exe to create a schema from.
vsdbcmd /a:Import /dsp:Sql /model:"Database" /cs:"Server=SqlServer; Initial Catalog=DatabaseName; Integrated Security=SSPI;"
The tool is reporting an error:
Error TSD02016, Gen-259 (12,50) The column name is not valid. No table name was specified.
How would I go about pinpointing where this error is originating?
I have found one resource on the internet (http://social.msdn.microsoft.com....) that points to a possibility of a keyword used incorrectly, but the error messages are not the same.
What is Gen-259?
Thank you,
Keith
I ran into a similar problem and was able to resolve it by using the import function in Visual Studio 2010. I created a new project and used Project -> Import Database Objects and Settings. In the our case, there were stored procedures that had become orphans and referenced columns in a table that no longer existed. We did have to correct some of the errors on the live system before we could get the project to fully import, but we were able to do that and create a .dbschema file which could be used as a reference in other VS projects.

Resources