Thursday, 26 November 2009

Intellisense isn’t working? An IntelliSensible list of Common Causes

Having been a fan of SQL Server 2008's Intellisense feature, I was disappointed to find it not working on a new installation of SQL Server 2008 (SP1-10.0.2531.0). I checked the Intellisense options (Tools>Options>Text Editor>Transact-SQL>Intellisense ) and it was showing as being enabled. I reviewed the other common cause of failure which is being connected to a database with a lower compatibility level than SQL Server 2008 (10) but this wasn’t the case.

I had a dig around and found the option to refresh Intellisense ’s local cache (edit>Intellisense >Refresh Local Cache), which worked for me and Intellisense sprang into life.

Curiosity persisted though, and I found the following guide to common causes of Intellisense failure. Hope it saves you some time in your investigations…

 

From MSDN:

There are certain cases when the Intellisense options might not work as you expect.

clip_image001 Conditions That Affect Intellisense

The following conditions might affect the behavior of Intellisense :

  • There is a code error above the cursor.
    If there is an incomplete statement or other coding error above the location of the insertion point, Intellisense may be unable to parse the code elements, and therefore will not work. You can comment out the applicable code to enable Intellisense again.
  • The insertion point is inside a code comment.
    Intellisense options are not available when the insertion point is within a comment in your source file.
  • The insertion point is inside a string literal.
    Intellisense options are not available when the insertion point is inside the quotation marks around a string literal, for example:
    WHERE FirstName LIKE 'Patri%|'
  • The automatic options are turned off.
    Many Intellisense features work automatically by default, but you can disable any feature.
    Even when automatic statement completion is disabled, you can use an Intellisense feature. For more information, see How to: Modify Intellisense Options.

clip_image001[1] Database Engine Query Intellisense

The following issues apply to the Database Engine Query Editor:

  • The Intellisense functionality of the Database Engine Query Editor does not support all Transact-SQL syntax elements. Parameter help does not support the parameters in some objects, such as extended stored procedures. For more information, see Transact-SQL Syntax Supported by Intellisense .
  • Intellisense is only available when the Database Engine Query Editor is connected to an instance of the SQL Server 2008 Database Engine. Intellisense is not available when the Query Editor is connected to earlier versions of the Database Engine.
  • Intellisense is turned off in the Database Engine Query Editor when the SQLCMD mode is set on.
  • Intellisense functionality does not cover database objects created by another connection after your editor window connected to the database. You can choose one of these three mechanisms to refresh the cache of objects for your editor window:
  • Select the Edit menu, select Intellisense , then select Refresh Local Cache.
  • Use the CTRL+Shift+R keyboard shortcut.
  • Disconnect your editor window from the instance of the Database Engine and reconnect.
  • Completion lists do not include database objects for which you do not have permissions. Intellisense flags references to objects for which you do have permissions. For example, if you open a script that is written by someone else, any references to objects for which that person has permissions and you do not are flagged as incorrect.
  • Completion lists might stop working if you lose the connection to the instance of the SQL Server Database Engine. Reconnect to the instance.

2 comments:

  1. Hi

    I have not seen anywhere what permissions are required on the database (everyone isn't an admin), do you know of what is required?

    ReplyDelete
  2. The short story:
    grant exec on xp_instance_regread to public

    The long story:
    We recently upgraded our user testing database to 2008. Intellisense did not work until we tried granting my user SA rights. This prompted us to search for the permission required. The MSDN articles insisted that you will be able to use Intellisense on objects that you have access to, yet I was unable to get Intellisense working on tables I could select from.

    I then went to ServerName -> Security -> Logins and tried to view the properties of my login. I got an execute denied error for xp_instance_regread. It turns out that this solves another issue in SSMS 2008 when trying to right click on non-2008 databases. Granting access to this enabled Intellisense.

    ReplyDelete