Update Target Button is disabled in Sql Server Database Schema Comparison - tsql

I use Visual Studio 2013 Professional Update 4 in combination with multiple SQL Server 2012 Enterprise servers/instances. The Idea was to create a Version controlled deployment using a Visual Studio Solution with SQL Server Projects.
However for some reason the "Update Target" and "Generate Script" button is disabled.
I can update the local database project from the sql server database but the other way around is not working. (see screenshot)
Google is not helpful at all although I found a few people with a similar problem.
Update target button is disabled after schema comparison
VS2012: Schema compare, update button disabled
VS2012 Schema compare buttons disabled
But none of this questions/blogposts is about Visual Studio 2013 and in addition none of the proposed solutions is working for me.
Question: Why is the Update Target button disabled and what do I have to change to fix this?
Note: Of course, I'm using the latest version of SQL Server Data Tools(12.0.50318.0)

This was driving me nuts, as well. I finally noticed a "warning" message stating "Cannot generate deployment plan due to an internal error". Because of this, the Update and Generate Script buttons were both disabled.
I resolved this by closing Visual Studio, navigating to the folder containing the Database project and removing all (*.dbmdl) files. I then restarted Visual Studio, re-ran the compare schema and the Update button was enabled.

The tip that helped me was to look at the error list. (View Menu, Error List). Once I cleared the errors (just the errors, the ones with the red X) I was able to compare the schema again and the Update and Generate Scripts buttons were both enabled.

Beside the generate script, click on OPTIONS and select only the objects for which you want to compare.
This and ONLY this worked for me.

Related

Visual Studio 2017 Communnity Incorrectly Updates Roslyn Scripting

I am using Roslyn for application scripting via Nuget Package Manager. Setup should be rather simple. Create new project and, in Nuget manager, add Microsoft.CodeAnalysis.Sripting package. After couple of confirmations you are ready to go.
Next step should be checking for installed packages update. Currently, there are 5 updates that are shown after initial installation. Again, it is pretty straightforward to do this.
However, immediately after the update, two of those packages show yellow triangle in Reference node of the project.
I have tried to resolve this following SO and other hints but nothing helped me so far.
At the end, I have installed new VM with Windows 10 Pro (with all updates) and VS2017 Community Edition. After that new Windows Forms project (.net 4.6.1. based for x64) was created and scripting package is added. Unfortunately, yellow triangles are still there (after update).
Problematic packages are System.ValueTuple and System.Security.Cryptography. X509Certificates.
Also, after cleaning and rebuilding the solution, a number of warnings (MSB3836) - explicit binding redirect on "System..." conflicts with autogenerated binding redirect.
Solution to this problem might shed a light on problem with more complex solution that I stumbled upon after migration to VS 2017.
So, what is the reason for such behavior? Remember, this happens on new installation of OS and VS with simplest project possible.
Visual Studio 2017 Communnity Incorrectly Updates Roslyn Scripting
I got the same result with you steps. This issue only occurred on the Visual Studio 2017 not Visual Studio 2015. That should have some issue with package Microsoft.CodeAnalysis.
To resolve this issue, I would like provide you a workaround:
Update packages "System.ValueTuple" and "System.Security.Cryptography. X509Certificates" first, then update other packages.
It works fine on my side, you can check if it works for you.
In order to track this issue, I have create a new issue on GitHub:
https://github.com/dotnet/roslyn/issues/22290
If you have additional information to add, you can add comments below that issue. And you can check the feedback from this link.

Visual Studio thinks correct SQL syntax is incorrect

In Visual Studio 2013, I have created a database project and imported an existing database. At first all was fine, and the project built and produced create scripts.
However, now Visual Studio seems to think that there are SQL syntax errors, returning several SQL46010: Incorrect syntax near: errors. These are all from code generated by VS - I have not written any of it.
Example 1:
ALTER ROLE [db_owner] ADD MEMBER [SomeUser];
SQL46010: Incorrect syntax near ADD.
Example 2:
DECLARE #Foo NVARCHAR(7) = 'abcdefg';
SQL46010: Incorrect syntax near =.
If I copy/paste the code into SSMS, everything works fine.
Unfortunately, these prevent the project from building, which means I can't publish. Since they are errors, not warnings, I cannot set them to be ignored in the project settings.
A workaround exists where I can set the problem files' Build Action to None, but I need these files included when I publish.
I have tried:
Deleting and re-adding the same code
Copy/pasting code to new SQL file
Closing and reopening the solution
Closing and reopening Visual Studio
Updating Microsoft SQL Server Data Tools (SSDT)
Updating Visual Studio
The closest problem I have been able to find is this MSDN thread from 2012, stating that there is a bug SSDT SQL parser (which prompted me to try updating SSDT).
There is a setting in the project properties called Target platform that tells VS what version of SQL Server to check the syntax against.
These are relatively new additions to the T-SQL syntax, and they might not work if the syntax was set to e.g. SQL Server 2005.
Old thread but this did catch me out so I thought I'd share my experience, the documentation for ALTER ROLE seems to indicate that it is supported on SQL 2008 when in fact only part of the functionality is. You can use Alter Role to change the name of a Role i.e. ALTER ROLE [ROLE NAME] WITH [NEW ROLE NAME]
But to add or remove members from the role it is necessary to use the old (and now deprecated) stored procedure sp_addrolememeber i.e. sp_addrolemember 'Role Name', 'User Name'.
As Aaroninus points out if you target SQL 2012 or later this will not report as an error.
In my case I was adding already existing post deployment script(.sql file) by clicking on a folder named "Reference Data" ==>Add Existing Item==>Select List of .sql files including the Script.PostDeployment1.sql file. On pressing F5 it was giving following error:
SQL46010: Incorrect syntax near :.
contents of sql file were :
:r ".\Customer.data.sql"
GO
:r ".\Product.data.sql"
GO
:r ".\OrderType.data.sql"
GO
:r ".\Orders.data.sql"
GO
Solution:
Post Deployment script should be created using VS.In existing project,open Visual studio and add post deployment script by clicking on : Add==>New Item ==>Script ==>Post Deployment Script ==>.PostDeployment1.sql.After creating PostDeployment1.sql file simply copy paste your content an then press F5..PostDeployment1.sql should execute correctly without any error.
having to set a flag in the project is really stupid since i've got ddl sql scripts in both oracle and mssql inside my c# class project.

unspecified error when binding to source control in VS2013

just upgraded a VS2010 project to VS2013. Project was already under source control in TFS.
Now everytime i open the solution, i receive a box that states something like "Project is already under source control but is not currently configured to use integrated source control. Would you like to configure now? Yes or no"
So if i click on 'Yes' it brings up the 'Change source Control' which shows it not connected to any server or anything. I am unable to click on the 'Connect' checkboxes and if I click 'bind' it will throw an 'unspecified error'
Help please. I need to ensure i can check in/out changes so that other developers are able to get the latest.
After investigate a few about your problem, i think you have two options:
Make a new repository with your project using vs2013.
Use your project (that is on TFS) with vs2010.

Unable to add Solution to TFS 2010 due to existing (invisible)binding

I have a smallish utility library I made that I had created in TFS Beta 2 to test out TFS. I now have TFS rc1 installed(and Beta 2 uninstalled) and am trying to add my Solution to TFS.
I get an error saying that it is already bound to my old TFS, which was on a different system then this one. Strangely, when I go into Source Control and look at the bindings it says there aren't any. Also, I manually deleted the .vss and .vsc files and it still does it.
Ideas? I looked through the numerous other SO topics related to this but unless I missed one none of them are dealing with my issue.
Ideas?
Grab the TFS Sidekicks from Attrice. They have a workspace sidekick, you can pretty quickly find your old machine and unbind/delete that workspace from TFS.
Once you install:
VS Menu Bar
Tools
Team Foundation Sidekicks
Workspace Sidekick
Owner will defult to you, just clear machine name
Search
Select old workspace, click the red X to delete
I had old server entries too and I fixed it by using the workspace sidekick mentioned here and then using the command line to get the rest that the tool couldn't find.

What do you do if the file in TFS is locked by someone else?

Someone left the organisation but before leaving, he locked all the files for an unknown reason.
How do you unlock them all so that the other developers can work?
For the following operation, you will need to be either a project administrator for the project you want to undo the check-in on or a Team Foundation Administrator if you want to do this across all projects.
If you still have the username of the person, you can simply do something like this:
Open up Visual Studio command prompt (Start -> Programs -> Microsoft Visual Studio 200X -> Visual Studio Tools -> Visual Studio 200X Command Prompt)
Run the following command:
tf lock /lock:none
/workspace:WorkspaceName;USERNAME
/recursive $/
To get the list of workspaces for a user, just run the following command from the same prompt:
tf workspaces /owner:username
For more commands, check tf /?
If the developer has left the organization, then the best thing to do is to delete their workspaces. This will unlock the files for you but also free up some resources on the server.
See the following blog post I did on the topic when it happened to me a few years ago.
http://www.woodwardweb.com/vsts/unlocking_files.html
You can either delete the workspace using the command line (tf.exe) or you can use the excellent TFS Sidekicks from Attrice.
This was the only way I resolved this, which involved deleting the user's workspace.
If the error message says "The item $/... is locked for check-out by someUser:1 in workspace someMachine123." then I use the command:
tf workspace /delete /server:http://machinename:8080/tfs/DefaultCollection someMachine123;someUser:1
There is just a single space between the collection URL and someMachine123;someUser:1.
Note that I payed attention to the fact that the error message mentioned the user as someUser:1, so I mimicked that in the command. It was not enough to just run the command with someUser only. I'm not sure what the :1 is all about but point being, mimick the error message.
Note the server has to be the fully qualified collection path, which you can find by going to Team Foundation Server Administration Console->Application Tier->Team Project Collections, the bottom pane will show a URL for the collection that is selected in the upper pane.
I also had a problem because I accidentally tried to use plural workspaces instead of just workspace because there is a similar command that is plural.
first you need to have the right to do this. If you have that the easiest is to use TFS sidekicks from attrice http://www.attrice.info/cm/tfs/
Here's an explanation of using TFS permissions.
Having the "Unlock other user's changes"
permission set to Allow is required to
remove a lock held by another user.
I needed to add /collection:collectionURL otherwise the workspace could not be found:
List item
tf loc /lock:none /workspace:WorkspaceName;UserName /collection:collectionURL
Have a system administrator reset that users password, log on as that user, unlock all files...
I would think this is the solution to almost all 'someone who is no longer at this organization' questions...
It is better to delete the workspace of that user from the server. example
tf workspace /delete /server:your_tfs_server workspace;username
Sometimes this is masking an different problem with a completely different application is locked by another user, but you cannot even create a New Folder for the new project you wish to merge into ( target won't allow the creation and incorrectly stating that someone has a file locked in their name) but then you dig deeper and another project is the culprit.
So a completely different project can be the problem with it having files locked by someone else.
Method that worked for me, my account has administrator permission on TFS and project :
In Visual studio 2015:
Go to Team Explorer
Click right on your solution and choose Open in source control
exporer
On left side click right on your solution
Choose Advanced
Choose Lock...
On left side click right on your solution
Choose Advanced
Choose Unlock (Now you can choose unlock)
Right now, every dev can easily commit his changes :)
by using TFS permissions,
Open up Visual Studio command prompt,Run the following command:
tf undo /workspace:workspaceName;DomainName\UserName $/file path in your solution
Use this solution as the very last resort.
I’m using TFS 2012. I went to the TFS database and ran the following queries. And it worked! Of course be very careful when messing with the database, take backups, etc.
The database is called Tfs_<<your_TFS_collection_name>>. Ignore the Tfs_Configuration MSSQL database. I'm not sure but if you don't have a Tfs_<<your_TFS_collection_name>> database, settings might be in the Tfs_DefaultCollection database. Locks are stored in tbl_PendingChange.LockStatus.
/*Find correct row*/
SELECT LockStatus, PendingChangeId, *
FROM tbl_PendingChange
WHERE TargetServerItem like '%<<fileName>>%'
/*Set lock status to NULL (mine was set to 2 initially)*/
UPDATE tbl_PendingChange SET LockStatus = NULL WHERE
TargetServerItem like '%<fileName>>%'
AND PendingChangeId = <<PendingChangeId from above>>