5

When I go to File > Open > File and select a .sql script, or even when I drag a .sql file into the SQL Management Studio Express window, it opens the script in Notepad which is totally useless when I want to run the script.

Since this is on an external server (Windows 2003 Server), I end up having to disconnect from RDP, disable the local clipboard, re-connect and then copy-paste the script's contents from Textpad in order to run it.

I've checked the options menus but can't see anything relating to Notepad, not even in the "external tools" section. Any ideas why it would be doing this?

Please note: I have checked the file association for SQL scripts and it is set to SQL Management Studio Express.

skaffman
  • 398,947
  • 96
  • 818
  • 769
tags2k
  • 82,117
  • 31
  • 79
  • 106
  • 1
    Out of interest if you double click on the Script file in Windows Explorer what does it load into? – kevchadders Jul 10 '09 at 14:18
  • It loads Management Studio, then opens my script in a Notepad window! – tags2k Jul 10 '09 at 14:28
  • Re-associate the file type even if it says it's already associated to SQL Server Management Studio - Try to set it to notepad and then back to SQL Server Management Studio. – dance2die Jul 10 '09 at 16:18
  • Does any of the below answers work for you, if they dont add a comment and I will see what else I can do for you. – Lima Jul 13 '09 at 07:38
  • Unfortunately not, I may just resort to re-installation of Management Studio when I get a free minute! – tags2k Jul 14 '09 at 07:33

4 Answers4

8

Ran into this this morning. Turned out to be an encoding issue for me. I opened the script up in UltraEdit and I noticed that it was showing the encoding to be U-DOS instead of DOS. I ran the Unicode to ASCII conversion (also in UltraEdit), saved the file, and now Management Studio is opening up the files correctly.

NFrank
  • 146
  • 7
  • How does this work with nvarchar or ntext content? Some of my scripts contain "foreign" languages, so converting to ANSI isn't going to help. – tags2k Aug 02 '09 at 08:23
6

I encountered this too - thanks NFrank for spotting the issue:

This was caused by opening the script in TextPad and accidentally saving as Unicode. The issue is not related to file associations.

The solution: Open in Notepad (or TextPad) - Save As... and select Encoding: ANSI

tranquil tarn
  • 1,606
  • 1
  • 13
  • 11
1

UPDATE:

In SQL Management Studio,

Go to File > Open > File,  
Highlight a SQL file,  
Click the down arrow on the Open button.   
Select Open With... 
Select SQL Query Editor 
Press the Set as Default button.

Matt

Lima
  • 1,203
  • 3
  • 22
  • 51
0

The first thing I'd check is to see if the application associated with SQL files on that box is Notepad.

Stephen Wrighton
  • 36,783
  • 6
  • 67
  • 86