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.
Related
I'm new to SSIS. I have a DataBase from which i'm getting the data. Suppose DB is the source and destination may be anything. (I tried DB to Excel and it worked fine)
In the source i have a custom query to get the data. I have written that in the properties.
Now i want to change it. I want to put it in some configuration file (xml file). i.e., i want to
get the query of the source from the xml file. How can i do this?
I'm a complete newbie trying the things. So please give your answer specifically.
UPDATE:
This is my package
I double clicked the OLE DB source. Now This is what i written there
I want to put the query (select id, age from emp where exp > 4), in a configuration(xml) file.
Create a package level variable for your query:
Change your source editor to use SQL command from variable (with appropriate variable) instead of SQL command:
Go to the SSIS menu and click "Package Configurations..." then click the checkbox to Enable package configurations, then click the "Add..." button.
... By default, it uses an XML Configuration file, which is probably easiest to work with. Specify a filename - the file extension is .dtsConfig. If the file doesn't exist on your machine, it will create one for you. Click Next.
Find your Variable, find the Value property for the variable, and check the box for it. Click Next.
Choose a name for your configuration. Click Done, then click Close in the Package configuration list, making a note of where on your file system you saved your configuration file.
Find the configuration file on your file system. Right-click and edit with an XML editor as needed.
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.
I am new to vb.net. I am creating a program with vb.net. The program has a database. It should have the ability to add an exe file to its database and as reference. When the exe file is added to database it can be run by clicking on an Icon.
I solve the database problem. I can add the exe file to my database and run it. However, the main problem is to add the file to my project references automatically. I mean I want to add the exe file by selecting the file with openfiledialog or something like that. This way, I will be able read some data from the exe file and add them to a database.
For example, My project name is "MY Project". When I run its exe("My Project.exe"), in its menu, I have a button named("Import exe.file"), when I click that button, a window is opened for selecting the exe file.when the file is selected, the program automatically add the exe file to its database and add the file to "My Project" references.
I didn't find any code to add a file to references.
Any help is greatly appreciated,cause I spent more than 2 weeks on this problem, without any progress.
Thanks,
Sepehr
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.
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.