Stop showing SQL errors in Visual Studio 2010 - sql

How can I stop VS2010 showing errors in .sql files, attached to a project? I don't want to check them at all, just C# code. The files are used as resources, Build Action set to Content. I'd like to keep .sql extension for syntax coloring purpose.
Regards,

Looks like your question was answered here: https://stackoverflow.com/a/8593877/2798869:
Visual Studio 2010
Tools -> Options -> Text Editor -> Transact-SQL -> IntelliSense
Uncheck "Enable IntelliSense".
Visual Studio 2012 & 2013
Tools -> Options -> Text Editor -> SQL Server Tools -> IntelliSense
Uncheck "Underline errors"
Note that you have to close then re-open any .sql files you may have open.

In VS 2012.
Go to the sql file properties in VS.
Under "Advanced", change the "Build Action" option to "None".
Unfortunately you have to do this for each sql file in the project.
This is what gave me the behavior that I wanted. It not only compiles without errors but shows no sql related build errors.
Update
It is possible to select multiple files in Solution Explorer by using Shift + Click (select the file at the top of the list -> hold down shift -> click the file at the bottom of the list). Once you have selected the group of files, you can then change the Build action to None for all of them at once. (This worked for me in VS2013.)
While you still have to select files per folder you don't have to select each file to set the property.

VS2015
right click in editor of the sql file > Intellisense Enabled

May be a sledge hammer to the problem but I manually deploy my SQL changes and only use them to house the scripts for my builds, so I do not need the functionality provided by SQL Projects.
Open the VS Solution File properties (right-click the solution in VS Solution Explorer and select Properties) and in the left pane select "Configuration Properties" -> "Configuration". In the right-pane you will see the projects in the solution. Un-check these projects to prevent them from building, this will prevent them from showing errors.

Is it possible you have a .cs extension on those files but it's not shown? I added some .sql files to my project and the compiler is not complaining.

Change the type of files to content and then the intellisense will never try and parse the contents of the files.

I just built a test project with one class file .cs and added one .sql file. It automatically set the build type to content. It built fine like John Fraser said in VS2010, so I changed it to compile, and obviously it failed.
This isn't the answer yet but perhaps the next step is to try and create a new solution, and import a few of the files from the original project to try to narrow down the source of the problem. If it builds then it would tell you it is something about the settings in your project/solution. Otherwise it could also be a VS setting.

Steps to stop showing SQL errors in bulk:
Open the SQL project file which has the .sqlproj extension in a text editor.
Find and replace <Build Include= with <None Include=. (This one has the same effect as right-clicking and changing Build Action to None in the solution explorer.)
The SQL errors should disappear in Visual Studio.

Related

Visual Studio 2013 Update 3 - No Intellisense?

Visual Studio 2013 Experts:
How do you enable intellisense when editing a single source file (or can you)?
Start Visual Studio 2013 Professional (Version 12.0.30626.00 Update 3 RC) -- fully registered.
Click on "File -> Open -> File ..." and select a VB.Net source file, ie: filename.vb
Type a statement such as:
if ( String.
^--- at that point isn't intellisense supposed to list
all members of the ASP.NET String class?????
Nothing happens; what setting am I missing?
OR
Does intellisense only work in Projects and not with individual source files?
Thanks in advance.
It depends on the file type. In your case, for a VB source file there will be no intellisense without a project.
On the other hand, for files such as Html, js it is available even without a project.
Intellisense only works when working within a project. The project type determines the internal compilers used to create intellisense - without this, you just have a plain text editor.

Resharper live templates in sql files

I created live template for creation of a stored procedure and I set availability in *.sql files. But when I'm in SQL file I don't have possibility to use live template by typing live template shortcut. I know that I have to change some setting in Visual Studio or in Resharper but I didn't find anything. Do you have any idea about that? I'm using VS 2013 and Resharper 8. Thank you.
Custom live templates should be able to work in .sql files.
You don't mention how you set your live template up, but here is how I acheived this with Visual Studio 2013 and ReSharper 8.2.
The example should allow you to type sf + TAB and get a select * from $TABLE$ template inside of a .sql file.
Go to ReSharper's Template Explorer via RESHARPER -> Templates Explorer...
Make sure you are on the "Live Templates" tab (the 1st one) of the Templates Explorer.
Under "Scopes" on the left side make sure "Global" is selected.
Click the new icon to bring up the template editor.
Add your template shortcut keys sf.
Add your template SELECT * FROM $TABLE$.
On the right side of the template editor window, select the link next to "Availability".
In the "Select Scopes" window that comes up, uncheck "Everywhere" and expand "In files matching".
Use the File mask *.sql
OK out and save your template.
The sf template should now be available in .sql files.
If you've followed these steps and it's still not working, you may have keyboard shortcut conflicts with another plugin. Consider reinstalling or repairing ReSharper or resetting the keyboard shortcuts via the RESHARPER -> Options -> Keybaord & Menus screen.
ReSharper's Live Templates only work in file formats that ReSharper supports, since Live Templates rely on other ReSharper features that need to understand languages, such as auto-formatting, name shortening and auto-imports and availability in scope. Also, Live Templates are inserted by selecting the item from ReSharper's code completion windows - if there's no code completion, there can't be any Live Templates.
Since ReSharper doesn't know about .sql files, you don't get Live Templates.

Where is the SQL File Template in Visual Studio 2010?

I notice in VS2010's Tools > Options dialog, there is a section on how to format the SQL:
I am working with a very large stored procedure on our server that is not formatted well at all. I was thinking it would be great to create a new SQL File in my project, copy and paste the text from the stored procedure in there, and have the text editor apply auto formatting to all of the SQL.
When I call "Add > New Item" and get that dialog, there does not seem to be any Installed Template with the .sql extension.
I see the SQL Server Database template, but that is not what I need. The LINQ to SQL Classes is not right, either.
What template do I need to use to use the auto formatting built into the VS2010 interface?
Judging from your screenshot, you have a C# project (e.g. a library dll) open. This won't show an option to add a .sql file as those files are not normally associated with a C# kind of projects.
One way around it is:
In VS2010 main menu, go to File -> New -> File. In General tab, there's a SqlFile file type.
Add a file and save it to the disk in the location of your project.
Right-click on your project and select Add -> Existing Item. In the open file dialog, change the extension to *.* to show your .sql file.
Add file to the project. If needed, change "Build Action" and "Copy to Output Directory" properties to control how it behaves during the build.
What you are looking for shows up when you create a SQL Server Database project.
File > Add > New Project
Then when you add items you see options that should work:
*Note my screenshots are from VS2012 - but I think it is the same.
I hate Visual Studio's T-SQL designer, even with SQL Data Tools installed. I opt to open my project's .sql files in Management Studio.
Right-Click any .sql file in VS.
Navigate to "Open-with"
Choose "Add"
In the Program dialog type "explorer.exe"
Type whatever you want for the friendly Name, I use Management Studio
Click "OK"
Highlight the new record and choose "Set as default".
Now double clicking any .sql file in VS will open up whatever program opens when you double click a .sql file outside of VS. Using this method, I'm able to edit, add, and modify my sql files in management studio and save them back to the project seamlessly.
Hope this helps.

Why would a .sln file open as empty in VB2010Express when it should open referring to projects etc. as it did before?

Why would a .sln solution file open and appear empty in Microsoft Visual Basic 2010 Express - i.e. no windows showing projects and code files etc.
When I inspect the file in a text editor, it contains references to vbproj files (which are present) which indicate that it should not appear as empty.
No error messages are reported when the file is opened.
Update:
(To illustrate my problem)
It attempts to load the projects that belong to the solution:
And then results in a bare solution screen
Express Edition is limited to on project per solution. If you have more than that, you will not be able to use the solution file with the express edition of visual studio. You will need to open the projects separately.
The answer is that the projects did load for the solution but the Window to display them was not open or visible. To make it visible, go to the View menu and select Other Windows:
This displays the 4 projects referenced by the solution
Forgive me for blurring the project names but this might be commercially sensitive and therefore not for public awareness. But you get the picture.
In summary it was my lack of knowledge about the tool, though I had looked under the Window option first thinking along these lines, but the View menu is actually where one would go to display things about the project.
Thanks to everyone for your contributions.

View Designer Code in Visual Studio 2010

What is a standard way to open the Designer (automatically generated) code for a VB file?
As a workaround, I can get to it by searching the entire solution for some keyword that is usually only found in those files: Global, Partial, etc.
Open the Solution Explorer. Along the toolbar at the top there is a tool Show All Files (it is the 2nd from the left on my version of visual studio). Click on that tool. All of your Form files will now have an arrow beside them. click on that arrow to expand. Look for the code file named FormName.designer.vb. Double-click on it to open.
You have to click the "show all files"-Button. Then you can also see the Designer.vb-files.
Note: For C# and VS 2008, but the same applies to VB in VS 2010.
http://peterkellner.net/2007/12/31/visualstudioshowallfiles/
http://blog.brianhartsock.com/2009/09/14/visual-studio-tip-show-all-file/
Keyboard shortcut for Show All Files
Show All Files is a useful little button in the Visual Studio solution explorer to give us a full view of the directory structure our project files are sitting in. When it is off, we only see the files that are explicitly included in the project, but when it is on, we see everything. This makes it very easy to explicitly opt a file into the project without doing an add -> existing item -> find existing item in directory structure and add to project.
The default when creating a new Visual Basic application in Visual Studio is to not show all files, and unfortunatly there is no setting you can adjust to change that.
Open the code file, and in the top-right corner of the code window is a drop-down containing all methods. Open this and select "InitializeComponent".
A screenshot from a newer version. Visual Studio 2015 and 2017 will look like this.