SQL Prompt
Latest version: 5.3
Knowledge Base
Unable to cast object of type 'System.DBNull' to type 'System.String' (version 3)
Category: Troubleshooting & error messages
Date: 30 Jul 2009
Product: SQL Prompt
Versions: 3.0-3.9
When caching a database in SQL Prompt, you may be presented with one of the following errors -
"Unable to cast object of type System.dbnull to type System.String."
"An unexpected null value has been encountered while querying the database system tables. Please make sure that the database is in a consistent state by running DBCC CheckDB."
Often these errors are reported because SQL Prompt is unable to retrieve certain metadata from the server using the account that SQL Prompt is logged in as. You will need to first check the account permissions and make sure that the logon account meets the minimum requirements. Here is an article outlining the account permissions needed:
http://www.red-gate.com/supportcenter/Content.aspx?p=SQL%20Prompt&c=knowledgebase/SQL_Prompt/KB200708000105.htm
If the account is not the problem, then there may be an issue with the underlying schema. It is possible that there is some corruption or misconfiguration of an object or meta-data that SQL Prompt doesn't know how to handle. For example, we've seen this happen before when certain objects have been found to be without an owner. You may be able to find out more information if you use SQL Compare and compare the problem database with a non problematic database (SQL Prompt uses the SQL Compare engine to register the database). Hopefully SQL Compare should give you a better error message or point you towards the specific object that is causing the problem.
If SQL Compare doesn't present you with any extra information regarding the cause of the error, then you can do some further troubleshooting.
Start a default SQL Server Profiler Trace (http://msdn.microsoft.com/en-us/library/ms187929(SQL.90).aspx) on the server that is hosting the problem database. Re-run the SQL Compare comparison to reproduce the error. Stop the SQL Server Profiler trace and look through the results to find the last query run by the application "Red Gate Software - SQL Tools". Copy this query into a new Management Studio query window opened against the original database, and execute it. Have a look through the returned results for NULLs that exist in fields that shouldn't allow them. This should, hopefully, allow you to track down the object that is causing the issue. The results can often be hard to analyze and knowing where NULLs are allowed and where they're not sometimes comes down to experience. If you do require assistance analyzing the data then if you could send the query that you ran and your results set to support@red-gate.com, we'll look into it for you.
Document ID: KB200708000141 Keywords: SQL Prompt, SQL Compare, permissions, access, System.DBNull, Sys
Was this article helpful?
SQL Prompt
- SSMS failed to load SQL Prompt add-in 80070002
- No SQL Prompt menu appears in Query Analyzer
- SQL Prompt is showing an old version of my stored procedure (version 3)
- Removing menu items after uninstalling SQL Prompt and SQL Refactor
- A newly-created table exists, but it is not visible in the candidate list (version 3)
- Configuring permissions for SQL Prompt
- Using Intellisense or auto complete with a VS Web project (version 3.5)
- Uninstalling the Visual Studio 2005 add-in
- Unable to cast object of type 'System.DBNull' to type 'System.String' (version 3)
- Suggestions to improve performance for pre-formatted SQL (version 3.9)
- Changing the location of the settings, cache files and snippets folders
- Saving SQL Prompt options (version 3)
- SQL 2008 installation fails with Express Tools rule (version 3.8)
- Add-in failing to load into SQL Server Management Studio on Vista
- Removing SQL Server Management Studio Integration after uninstallation
- Layout SQL Error
- Downgrading to SQL prompt 3.9 from 4.0
- Candidate suggestions being displayed slowly
- SQL Prompt is not showing all linked servers
- Log files
- Refreshing the cache
all SQL products
- Compatibility of Red Gate tools in 64-bit environments
- Application has encountered an error and needs to close
- Error message after installing SQL Toolbelt - The description for Event ID ( 1 ) in Source ( nview_info ) cannot be found.
- Changing the temporary directory used by the installer
- Toolbelt Installer "hanging" while "scanning volumes"
- Login failing with "trusted SQL Server connection" error when using RunAs
all products
- Some Red Gate products identified as containing a trojan by Anti-Virus software
- Activation may fail with Unknown Error -1
- Product uses web help although a CHM file is available locally
- Argument exception resulting from missing environment variable
- Check for updates may fail when used through proxies
- 'Unidentified Publisher' error when repairing or uninstalling
- Licensing activates product as standard edition
- Moving Red Gate software products to another machine
- Red Gate tools log locations
- The application UI opening slowly when there is no internet access
SQL Prompt
- Activating your products
- Activating your products
- Getting help offline
- Customizing SQL Prompt to write SQL code more efficiently
- SQL Prompt 3.xx - reducing memory usage to improve performance
- Using SQL Prompt 4: tips for SQL Prompt 3 users
- SQL Prompt release notes - version 4.xx
- Release notes - version 5.xx
all SQL products
all products
- Red Gate product acknowledgements
- Activating your products
- Activating your products
- Red Gate bundle history
- Check for updates
- Troubleshooting Check for Updates errors
- Current versions
- Deactivating your products
- Installing Red Gate products from the .msi file
- Requesting additional activations
- Serial numbers for bundles
- Reactivating using a different serial number
- Extending your trial
- Finding your serial numbers
- Moving a serial number from one computer to another
- No response received for manual activation
- Licensing and activation resources
- Licensing and activation resources
- Troubleshooting licensing and activation errors
- Licensing and activation FAQs
- Red Gate tools log file locations
- Download old versions of products
- Download product prerequisites & utilities
- Support & upgrades
- Upgrading your software
- Upgrading FAQs

Using SQL Prompt