Change the default save location for SQL Management Studio 2008 [duplicate] - sql

This question already has answers here:
Management Studio default file save location
(16 answers)
Closed 8 years ago.
As the title states, how do I do this?
I want to hit save, and have SSMS automatically direct me to a network folder..

This is 3 years old now, but an answer for SSMS 2012 and 2014 would be helpful, so I thought I'd add an update. Step one differs between the versions, and then the rest is the same:
SSMS 2012
Locate C:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\ManagementStudio\Extensions\Application
SSMS 2014
Locate C:\Program Files (x86)\Microsoft SQL Server\120\Tools\Binn\ManagementStudio\Extensions\Application
Both (continued)
Open ssms.application.pkgdef with text editor(e.g. Notepad)
Change the value of DefaultProjectsLocation
"DefaultProjectsLocation"="$MyDocuments$\SQL Server Management Studio"
Save the file
Thanks to this source: http://www.networksteve.com/forum/topic.php/How_to_change_the_default_query_save_location_in_SSMS/?TopicId=41425&Posts=0

The correct location for 2k8 in the registry is HKEY_CURRENT_USER\Software\Microsoft\Microsoft SQL Server\100\Tools\Shell.

It's not editable from within the tool (for some reason), but you can adjust it from the settings file within My Documents > SQL Server Management Studio > Settings.
Look for the node "ProjectsLocation", and adjust accordingly -
<PropertyValue name="ProjectsLocation">\\mynetworkpath</PropertyValue>
Be sure to exit SSMS before editing this file. This should do the trick...

#Kevin's solution doesn't work for SQL 2k8. One needs to change the registry:
key = HKEY_Current_User\Microsoft\Microsoft SQL Server\100\Tools\Shell
Now see where they wrote the default path... change that into any valid UNC.

This seems to work for me after a lot of bungling -
Edit registry settings as outlined in above posts (HKEY_CURRENT_USER\Software\Microsoft\Microsoft SQL Server\100\Tools\Shell) - change all the paths EXCEPT MyDocumentsLocation (this is what seems to cause the settings to get reset).
Locate the .vssettings file from My Documents and copy to your folder + '/Settings' folder (e.g. c:\Dox\SQL Server Management Studio\Settings).
Start SQL studio, quit and restart.
Edit the .vssettings file (should be in your folder now rather than My Documents), and change the ProjectsLocation to the desired folder e.g. C:\Dox\SQL Server Management Studio\Projects
Start SQL studio. Opening files should now work, but save will require clicking the 'My Projects' on the left of the save dialog.

Related

How to open a very big file in Microsoft SQL Server Management Studio 2014?

I have a file about ~9GB. It's a file extracted from an old MS SQL server and I need to import it to a new one. The file has no extension.
When I try to open it through Microsoft SQL Server Management Studio 2014 I get the following error:
First of all, if you want to open a large file to read it, which i assume that it is not the case, pick one of the text editors from this post:
Text editor to open big files
And in case you want to execute really big SQL scripts, you will have to do it through the Windows CMD (or Bash in case you are using Ubuntu for example) using SQLCMD, have a look at this:
Execute large scripts using SQLCMD
I hope this is what you are looking for!

How to change the connection in Sql Server Data Tools Editor in Visual Studio

My goal is to keep SQL Server stored procedures under source control. I also want to stop using SQL Server Management Studio and use only Visual Studio for SQL related development.
I've added a new SQL Server Database project to my solution. I have successfully imported my database schema into the new project, and all the SQL objects (tables, stored procedures) are there in their own files.
I know that now if I run (with F5) the .sql files then my changes will be applied to my (LocalDB). This if fine, but what if I want to very quickly run something on another machine (like a dedicated SQL Server shared by the entire team)? How can I change the connection string of the current .sql file in the Sql Server Data Tools editor?
I have the latest version of Sql Server Data Tools extension for Visual Studio 2012 (SQL Server Data Tools 11.1.31203.1). I don't know if this is related to the current version, but I cannot find anymore the Transact-SQL Editor Toolbar.
I have also tried to Right-click on the sql editor, choose Connection -> Disconnect. If I do the reverse (Connection -> Connect...) the editor directly connects automatically (probably to my LocalDB), without asking me a dialog to choose my connection.
Another strange thing I've observed, if I try to run a simple SQL query (like select * from dbo.ApplicationUser I receive the following message (even if the autocomplete works):
Thanks.
(Note: I have the same issue with Visual Studio 2013)
Inspired by srutzky's comments, I installed the latest SSDT pack (12.0.41025). And bingo, like srutzky said there is a Change Connection option. But what's more, you can specify your Target DB by right clicking on the Project in the Solution Explorer, and going to Properties->Debug and changing the Target Connection String! If you're stuck on an older SSDT, then the below instructions will still work.
For SSDT 12.0.3-
I've also been plagued by this problem! My solution is below, but it has some Pros and Cons to it...
SOLUTION
I'm assuming that you are using a SQL Server Project in VS (I'm using VS2013 and SQL Server 2012).
Right click on your .sql file in the Solution Explorer and view Properties.
Change Build Action to None.
If the file is open for editing, then close it.
Reopen the file, and the T-SQL Editor should appear at the top.
Click Connect, and you will connect to your (localdb).
Click Disconnect.
Click Connect again and the SQL Server Connection dialog should appear.
Switch the connect string of '(localdb)\Whatever' to '.' (for some reason using '(localhost)' didn't work for me).
Voila, you should now be able to query against your SQL Server DBs! Rinse and repeat for every file you want this capability with... :/
PROS
You can finally run queries directly against your SQL Server DB
Your code can be organized in a nice VS solution (SSMS doesn't allow folders! :/)
You can (after switching Build Action setting back) Build the project
CONS
I'm not seeing any autocomplete/intellisense against the remote DB, although if you import your DB, then you could gain the intellisense from that
Requires each file to switch Build Action to None
This should be a fairly simple and straight-forward thing to do, that is, if you are using SSDT version 12.0.41025.0 (or newer, one would suppose):
Do either:
Go to the SQL menu at the top of the Visual Studio window
Right-click inside of the SQL editor tab
Go to Connection ->
Select Change Connection
Then it will display the "Connect to Server" modal dialog window.
If you do not see the options for "Disconnect All Queries" and "Change Connection...", then you need to upgrade your SSDT via either:
Visual Studio:
Go to the "TOOLS" menu and then "Extensions and Updates..."
Direct download:
Go to: http://msdn.microsoft.com/en-us/data/tools.aspx
The fastest way to achieve this is create a new SQL Connection, copy and paste the code then execute.
What I do is Tools->SQL Server->New Query.
Enter the database credentials (And make sure that the Database at the top is correct - I have hundreds of sp's in my master db on local :) )
Copy the source code from the editor, paste into the new query window.
Then Execute (CRTL-Shift-E).
You can leave this 'scratch' window open and pinned for easy access for subsequent executes.
If you want to deploy (i.e. publish) the entire database then you can setup a publish destination for each server, right click on the xml and select publish..

Beginner's SQL: How do I find a detached database?

I'm brand new to SQL and I'm practicing some queries with a DB.
I've now just detached the database using Tasks > Detach
Question 1: When I detach a file, I'm guessing it's saved to an MDF file? Where would I locate this file?
Question 2: When I create a new DB, where do the related files get saved? I'm assuming an MDF and an LDF set of files are created.
If it helps, here's my version info
Microsoft SQL Server 2008 (SP1) - 10.0.2531.0 (X64) Mar 29 2009 10:11:52 Copyright (c) 1988-2008 Microsoft Corporation Developer Edition (64-bit) on Windows NT 6.1 (Build 7601: Service Pack 1)
Thanks!
You can always look at the database properties in your Object Explorer in SQL Server Management Studio before detaching - the file(s) will not be moved or anything when detaching....
In the Properties dialog box, go to the Files section and to your right, the relevant info can be found:
SQL Server databases are .mdf files. When you detach, the .mdf file is closed by the SQL Server process, but it exists from the moment you create the database. Just to be clear, there is no concept of "saving" in an SQL DBMS; at least, not in the sense you are suggesting. Every transaction you perform is permanently stored from the moment it is committed.
When creating the database, the dialog box shows a list of files that will be created. You may have to resize some of the columns and scroll horizontally to see the full path. You can also see this information by bringing up the database properties dialog.
The .ldf file is the transaction log. It plays a vital role in ensuring the permanency of committed transactions.
Ok so if you have already detached the database, and then realized that you are clueless where it is, you can do this trick.
Expand server, then on Databases click Right Mouse then choose Attach...
Click Add...
Then in the new window that opens will be a path to the directory where your detached database is (if you haven't navigated from default location earlier)
Also, the default location for MSSql databases is:
C:\Program Files\Microsoft SQL Server\[YourSQLVersionGoesHere]\MSSQL\DATA
Hope this saves you some time.

SQL Server 2008 Express Clear Recent Connection List

I was trying to remove my recent connection list by deleting the mru.dat (in Application Data folder under windows xp) file as pointed out in numerous tutorial over the internet(I just googled it) but was unable to find it. How am I supposed to clear it? Please help.
See this blog post:
For SQL Server 2008:
C:\Documents and Settings\<user>\Application Data\Microsoft\Microsoft SQL Server\100\Tools\Shell\mru.dat
If you can not find mru.dat at above location look for mru.dat in following folder.
C:\Documents and Settings\[user]\Application Data\Microsoft\Microsoft SQL Server\100\Tools\ShellSEM\mru.dat
If you are using VISTA OS instead of XP OS. Replace C:\Documents and Settings\[user]\Application Data\Microsoft\ with
C:\Users\AppData\Roaming\Microsoft\ and it should work.
I was able to accomplish this using Tools -> Options -> Display X files in recently used list. Simply set it to 1 then back to 10. I had to fiddle with it and restart SSMS a few times. They might still be on the hard drive somewhere, but they don't show up in the MRU list.

Database Projects: Visual Studio 2008 vs 2010

I just installed VS 2010 for the purposes of running someone else's DB project that was created using the 2010. In VS 2008 I was able to right click on a SQL file ans select "Run ON" to run the script on a given SQL Server. I don't see this option in 2010. Is it available and if so how do I get access to it?
The database project format that was included in VS 2005 and VS 2008 has been completely removed in 2010.
Rather than holding loose SQL files that could be run independently, it acts a bit more like a compiler. When the project is built, the SQL files are parsed and (for the most part) turned into an XML-description of the database schema.
If you're trying to create or update a database based on all of the scripts in the project, right click on the project name in Solution Explorer and select "Properties". Under the Deploy tab youchange "Deploy Action" to "Create a deployment script and deploy to the database". Specify the connection settings and database name.
When you select "Deploy" on the right-click context menu of the database project, Visual Studio will build the database deployment files and generate the database. It's generally intelligent enough to update existing databases as well, assuming the project was designed well.
If you're attempting a remote deployment to a production SQL Server, things get a bit trickier. There is no single set of SQL files you can run - part of the database schema is stored as XML.
Take a look at Link - it describes how to use the "vsdbcmd.exe" utility to deploy a database file.
If you just want to run a single SQL file or test part of one, open the file, right click, and select "Execute SQL"
DNRTv # 167 talks about VS 2010 Database Projects in detail.
As #ShadowChaser already mentioned, DB Project in VS 2008 simply had the scripts in it, and 2010 version is a lot more complex and has a lot more features.