Open .sql extensions in ssms 2008 r2 rather than ssms 2012 - ssms

I want to open .sql extensions automatically in ssms 2008 r2 rather than ssms 2012 for reasons I won't bore you with. On Windows 7. It can't be done through the normal file types and default programs dialogues as it seems just to associate with the generic program rather than the version, so presumably I need to do something in the registry. Can anyone advise?
Many thanks,
James

Thanks Giorgi, but that didn't work for me. Maybe if I'd rebooted it might have done, but I didn't think we needed to do that these days.
Answer:
Download a 3rd party File Type Manager (Nirsoft FileTypesMan worked for me) and change the entries to the following:
Associate the following program (SSMS 2008 R2) with the file type:
"C:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\Ssms.exe"
Associate the following with the Open action:
"C:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\Ssms.exe" /dde "%1"
In the DDE details for the Open action, add the following:
Message: Open("%1")
Application: sqlwb.9.0
Ifexec: {leave this blank}
Topic: system

Related

SQL Server 2012 installation Reporting Services Catalog error

I'm installing SQL Server 2012 at the moment and when I was about to run the installation, this error pops up:
On clicking the first failed test, which is "Reporting Services Catalog Database File Existence", this is what i get:
On clicking the second failed test, which is "Reporting Services Catalog Temporary Database File Existence", this is what i get:
So basically, both of the message box says me that "Catalog Database File" & "Catalog Temporary database files exists". Because of this, i need to select Reporting Services file-only mode installation.
My questions are:
How do i select file-only mode installation?
Do i've to close the setup and do something and afterwards run the setup again?
Btw, I had SQL Server 2012 installed before. I uninstalled it completely due to some strange errors and decided to reinstall a fresh copy of SQL Server 2012 and now I'm stuck with these errors. Any help will be sincerely appreciated. :)
Since you already had one installation of SQL Server done before, there was a database already created. That did not get removed. So when you reinstall, its trying to create the database with the same name, hence, the error. You need to delete the old files to continue the new installation.
From the direcotry
C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA
Remove the following files
ReportServer.mdf
ReportServer_log.LDF
ReportServerTempDB.mdf
ReportServerTempDB_log.LDF
Try the Following link for further help.
Reporting Services Catalog Error.
For sql-server-2012 the path is:
C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQL2012\MSSQL\DATA
where MSSQL2012 is the instance name and the respective file names are:
ReportServer$MSSQL2012.mdf
ReportServer$MSSQL2012_log.mdf
ReportServer$MSSQL2012TempDB.mdf
ReportServer$MSSQL2012TempDB_log.mdf
Remove the following files from the C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA directory:
bulletReportServer.mdf
bulletReportServer_log.LDF
bulletReportServerTempDB.mdf
bulletReportServerTempDB_log.LDF.
This happens if you reinstall SQL Server and these files weren't deleted.

Unable to connect to SQL Server 2008 R2

I am unable to connect to a local SQL Server 2008 R2 trial version from Visual Studio 2010 Express.
When adding a new connection, I browse to the database file in this location:C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS\MSSQL\DATA\AdventureWorks_Data.mdf, I encounter this error:
Could not open new data base 'C:\PROGRAM FILES\MICROSOFT SQL
SERVER\MSSQL10_50.SQLEXPRESS\MSSQL\DATA
ADVENTUREWORKS_DATA.MDF'.CREATE DATABASE is aborted. An attempt to
attach an auto-named database for file C:\Program Files\Microsoft SQL
Server\MSSQL10_50.SQLEXPRESS\MSSQL\DATA AdventureWorks_Data.mdf
failed. A database with the same name exists, or specified file cannot
be opened, or it is located on UNC share. File activation failure.The
physical file name "C:\Program Files\Microsoft SQL
Server\MSSQL10_50.SQLEXPRESS\MSSQL\DATA\AdventureWorks_Data_log.ldf"
may be incorrect.
The log cannot be rebuilt when the primary file is read-only.
Another guess, you don't by any random chance have another user logged into the same machine that would have the DB file locked by connecting to it in the same way you say you're trying to? I'd imagine the previous comment about that database file already being attached to by the sql service is probably far far more likely, but just for wild chance I'm leaving my idea here for you or anyone else who happens by

How to open multiple .sql files in only one ssms instance

I'm DBA with a new server box running Windows Server 2008 Enterprise SP1 with SQL Server 2008 and SQL Server Management Studio.
In my previous box when working in Visual Studio with database solution with lot of .sql files I used to double-click on the .sql files and they were opened in the same SSMS instance (if any already opened). However (even when having exactly the same installation in the new box) I'm now getting a new SSMS instance when double clicking in each sql file. Its really painful one .sql - one SSMS instance so I started my research about that.
What I've tried till now:
1) Right click on the .sql file > "Open With" option > "Add" option > "Program Name: C:\Program Files\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\Ssms.exe" and "Friendly Name: SQL" > "Ok" > "Set as Default". Does NOT work. Still having one sql - one ssms instance.
2) Perfomed Run > regedit > and modify the value data of HKEY_CLASSES_ROOT\sqlwb.sql.9.0\Shell\Open\Command and replace /dde with "%1". DOES NOT WORK
3) Right click on the .sql file > "Open With" option > "Add" option > "Programe Name: explorer.exe" and "Friendly Name: Explorer" > "Ok" > "Set as default". Does NOT work. When double-clicking on the .sql files Notepad comes with scripts content.
4) Some pages like this
http://social.msdn.microsoft.com/Forums/en/sqltools/thread/ac2f39c5-66e5-495c-b7a6-47e743853baf
asks to change file association but when opening Windows Explorer > Tools > Folder Options ... I found there is no "File Type" tab. How annoying!
Can someone help me on that? My patient it's really running out.
Thanks in advance
After spending most of my working day looking for the solution I finally found it. Thanks God, I was almost running out with this issue. Hope it helps somebody else!!!.
Update: linked domain expired, so here's what it said:
Considering how integrated Microsoft tools usually are the result is
frustrating when you tell Visual Studio to open SQL files using Sql
Server Management Studio (SSMS). I really don't like using Visual
Studio to edit T-SQL files but in the past, before I discovered this
tip, each SQL file I opened would open in a new instance of SSMS. Try
it:
Open a solution which contains SQL files
Right-click any SQL file and select “Open With…”
Click “Add”
Browse to "C:\Program Files\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\Ssms.exe" or if you're
running x64 Windows "C:\Program Files (x86)\Microsoft SQL
Server\100\Tools\Binn\VSShell\Common7\IDE\Ssms.exe", then click “OK”
Click “Set as Default” and then “OK”
Now open multiple SQL files. Each time you'll get a different instance
of SSMS opened. What a pain!
NOTE: This entire article applies to SQL 2005, just replace SSMS with
SQLWB.
How do you resolve this? Repeat steps 1-3 above, but at step #4 enter
the following values:
Program Name: “explorer.exe”
Friendly Name: “Windows Explorer”
Repeat step #5 (set as default) above and then click OK. Now, open
additional files. They should all open in the same instance of SSMS.
It would seem that Visual Studio issues a command to SSMS.exe which
includes the path of the file selected in the solution explorer. It is
up to SSMS to check for a new instance, which it doesn't. But when you
pass the file name to explorer it gets opened up in the same instance.
QUIRK WARNING!
If SSMS is not already open, the first file you attempt to open (not
first time ever, but every time you open an SQL file from Visual
Studio and SSMS isn't open yet) SSMS will open, but your file will
not. Click the file a 2nd time and it will open the file this time.
Don't ask me to explain it it just is (and I have no idea why).
Conclusion
The result when you tell Visual Studio that SSMS is the default editor
makes sense, but I don't get why it would be different when you tell
explorer to open it. Maybe if I were a Windows developer instead of a
web developer I would know the answer. But either way, now you know.
Enjoy.
I have this problem before, I found there is a simple solution -> just check if your SSMS is under "Run this program as an administrator" option (right click on the shortcut icon -> property -> Compability -> Privilege level). If yes, untick the option and try double click the sql file.
Hope this helps.
Similar issues have been reported multiple times, but they aren't addressing the issue (removed links because Microsoft erased Connect without much thought):
~connect.microsoft.com/VisualStudio/feedback/details/105575/multiple-instances-of-sqlwb-exe-when-management-studio-set-as-default-editor~
http://web.archive.org/web/20130727043341/http://connect.microsoft.com/SQLServer/feedback/details/622181/multiple-ssms-open-for-seperate-sql-files
~connect.microsoft.com/SQLServer/feedback/details/680761/a-new-instance-of-ssms-is-opened-when-trying-to-open-a-tsql-file-even-when-an-instance-is-running~
Did you install Visual Studio (or any Visual Studio components) after installing SQL Server?
My guess is that the Connect items will not be fixed - SQL will blame Visual Studio, Visual Studio will blame SQL, and the items will remain open...
So here is what I suggest: run a repair of SQL Server from Programs and Features and then re-apply the latest service pack of SQL Server 2008 (SP2).
Also the "File Types" interface was moved from the Tools / Folder Options interface to the Control Panel. Go into Control Panel > Default Programs > "Associate a file type or protocol with a program." However it doesn't seem to have the options here to add command-line options like "%1" or /dde.
Try adding these reg keys as well, but make sure you put the /dde back in:
[HKEY_CLASSES_ROOT\sqlwb.sql.9.0\Shell\Open\ddeexec]
#="Open(\"%1\")"
For the record, here is my entire export for that section:
[HKEY_CLASSES_ROOT\sqlwb.sql.9.0\Shell\Open]
[HKEY_CLASSES_ROOT\sqlwb.sql.9.0\Shell\Open\Command]
#="\"C:\\Program Files (x86)\\Microsoft SQL Server\\100\\Tools\\Binn\\VSShell\\Common7\\IDE\\ssms.exe\" /dde"
[HKEY_CLASSES_ROOT\sqlwb.sql.9.0\Shell\Open\ddeexec]
#="Open(\"%1\")"
[HKEY_CLASSES_ROOT\sqlwb.sql.9.0\Shell\Open\ddeexec\application]
#="sqlwb.9.0"
[HKEY_CLASSES_ROOT\sqlwb.sql.9.0\Shell\Open\ddeexec\topic]
#="system"
Go to Tools >> Folder Options >> File Types and apply below settings. It worked for me finally!!! (after half a day search on google).
Click New/Edit (on this window "Confirm open after download" should be check and "Always show extension" should be unchecked)
In next window, make below entries
- Action: Open
- Application used to perform action : Your ssms.exe path like "C:\Program Files\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\Ssms.exe"
- Check "Use DDE" check box
- DDE Message : Open("%1")
- Applicajtion sqlwb.9.0
- DDE Application Not Running: Keep it empty
- Topic : system
Regards,
Sandeep Gaadhe
I am using SQL Server Management Studio 2012 Express and I have made this to work by pointing "Program" to "explorer.exe"
This is how my register is set up: "C:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\ManagementStudio\ssms.exe" /dde
at
HKEY_CLASSES_ROOT\ssms.sql.11.0\Shell\Open\Command
I've 2005 & 2008 SSMS installed so I defaulted to the 2005 instance. If I have 2008 ssms open when opening a .sql file from windows explorer it will now open in the existing 2008 ssms (and not try to open a new instance!)
From Windows Explorer, one can drag-and-drop selected files (single or multiple) into an SSMS window.
One thing to check is if you have multiple versions of SSMS. If you happen to be working in an older version, double clicking on a file will open the new SSM version. Or whatever the default version is for sql files.
A quick note for users who want to have SSMS always open with Administrator privileges.
Find SSMS in your start menu. Right-click>More>Open File Location.
Once you see the shortcut to Microsoft SQL Server Management Studio * in Windows Explorer, Right-click>Open File Location.
Then Right-click on Ssms.exe>Troubleshoot compatibility.
Then click Troubleshoot program.
Put a tick by The program requires additional permissions then hit Next.
Now it forces you to press Test the program....
Then press Next and then Yes, save these settings for this program.
Arvo Bowen Jan 30 '20 at 15:27
This work perfectly.
I know this is quite an old post and there are loads of different answers with possible solutions. But here's one I think is new (at least to SO).
I suddenly starting getting this behaviour (i.e. each new file would open in a new session) and couldn't figure out why. Turns out it was because in my SSMS session I had an open dialogue which had dropped into the background.
A soon as I closed the dialogue, new files started opening in my original session /facepalm
Maybe everyone knows this already but just in case it saves anyone 20 mins!
My issue with multiple SSMS instances version 19 was fixed by changing HKEY_CLASSES_ROOT.sql Default key to

sp_attach_single_file_db Error: failed with the operating system error 5(Access is denied.)

I'm trying to use this DataBase that come with this sample project with from MS:
http://code.msdn.microsoft.com/ASPNET-Web-Forms-6c7197aa/sourcecode?fileId=18930&pathId=365206059
So after I downloaded the files: I need to attach the .mdf DataBase to my Instance of MS SQL 2008.
From Management Studio Attaching DataBase does not work and event using this command i receive the same error:
sp_attach_single_file_db 'School.mdf', 'C:\School.mdf'
ERROR:
Msg 5133, Level 16, State 1, Line 1
Directory lookup for the file "C:\School.mdf" failed with the operating system error 5(Access is denied.).
Any idea what is wrong? Thanks for your help!
Give full permission on folder in which you want to create the mdf file
to the logon account with which the SQL Server service is running.
Usually: NT Service\MSSQL$
You can look that up
Control Panel-> Administrative Tools-> Services=> SQL Server -> Prperties-> Logon Tab-> Note the account
What operating system are you running on? Did you get an elevation prompt when you saved the file to the root of the C drive? What user account is SQL Server running under, and does it have permissions to read any files in the root of the C drive?
You might do better placing the file into %ProgramFiles%\Microsoft SQL Server\MSSQL10.<instance name>\MSSQL\DATA, alongside the other .mdf files that you know it can already read (adjust path above as necessary, but you hopefully get the idea).
I had this issue and all the solutions online was misleading.
The solution was to open SSMS as Administrator. In my opinion first try this and later try all other solutions.
Moving it to DATA folder basically resolved permission issue. Another solution is to change the permissions of the file (or files) and thus still have DB in different folder. I just ran into similar permission error "CREATE FILE encountered operating system error 5(Access is denied.)" trying to attach DB in SQL Server 2012 express on Windows 7.
Solution I did was following:
1) Rich-click on each MDF, LDF, and NDF file to get menu --> select properties
2) Add Users for computer and give them full control (instead of Everyone - to dangerous)
After that I could attach the DB.
However, even if not moved to DATA folder, should move into subfolder instead of C:\ root (example: C:\mydb).
create DATABASE newDataBaseName
on (FILENAME = 'C:\Program Files (x86)\Microsoft SQL Server\MSSQL12.SQLEXPRESS\MSSQL\DATA\filename.mdf'),
(FILENAME = 'C:\Program Files (x86)\Microsoft SQL Server\MSSQL12.SQLEXPRESS\MSSQL\DATA\filename_log.ldf')
FOR ATTACH_REBUILD_LOG;
GO
Also as Damien mentioned above put the mdf files in the where your other mdf files are located. For me C:\Program Files (x86)\Microsoft SQL Server\MSSQL12.SQLEXPRESS\MSSQL\DATA
In my case I found the Directory lookup needed the computer/users group in read/list permissions. While the service and the actual user running the (in my case) restore had full permissions that permission was important.
Security wise I hate it.

SQL Server 2005 backup restore failing (with folder permissions)

I am trying to restore a database (from file thedb.bak). I am using SQL Server Express edition 2005 on a Windows 7 Ultimate 64-bit machine.
When I try to restore I get the following error:
System.Data.SqlClient.SqlError: The operating system returned the error '5(Access is denied.)' while attempting 'RestoreContainer::ValidateTargetForCreation' on 'C:\Program Files (x86)\Microsoft SQL Server\MSSQL.2\MSSQL\Thedb.MDF'. (Microsoft.SqlServer.Express.Smo)
My username (antoniocs) is an Administrator. I have edited the permissions in the folder (C:\Program Files (x86)\Microsoft SQL Server\MSSQL.2\MSSQL\) so that the user AntonioCS has full control.
I really need to restore this backup. What am I missing?
Note: I am using the Windows authentication to login. Should I try another user (the one I use is an administrator in the machine)?
The account running the SQL Server service requires permissions on that folder.
You may be connected to SQL Server, but actions are done in the service account context: not you.
Run services.msc from command line, see what account is used, permission this folder accordingly.
Do you have a database that uses Thedb.MDF? I ran into this error when I tried to restore a database over a file that SQL Server used. From the restore window, choose Options and change the path or the filename from the "Restore the database files as".