<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://sqlblog.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Search results matching tags 'Security', 'management studio', and 'database list'</title><link>http://sqlblog.com/search/SearchResults.aspx?o=DateDescending&amp;tag=Security,management+studio,database+list&amp;orTags=0</link><description>Search results matching tags 'Security', 'management studio', and 'database list'</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP2 (Build: 61129.1)</generator><item><title>For shared SQL Server providers : hiding your list of databases from customers</title><link>http://sqlblog.com/blogs/aaron_bertrand/archive/2009/07/19/for-shared-sql-server-providers-hiding-your-list-of-databases-from-customers.aspx</link><pubDate>Sun, 19 Jul 2009 15:26:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:15339</guid><dc:creator>AaronBertrand</dc:creator><description>
&lt;p&gt;In a shared SQL Server hosting environment, there are several problems that can arise when you let your customers use Management Studio to connect and administer their databases.&amp;nbsp; In the typical case, you give them a single SQL Authentication username and password, and they are supposed to be able to connect only to their database.&amp;nbsp; By default, however, Object Explorer and Object Explorer Details will gladly present the entire list of databases on the server.&amp;nbsp; In this case, not only are you exposing all of your customers' database names to each other, and letting your customers know exactly how many databases are sharing the server, but you also introduce the chance for customer support calls.&amp;nbsp; This is because of at least two factors:&lt;br&gt;&lt;br&gt;(a) enumerating all of the databases on the server can take a long time, and could potentially time out;&lt;br&gt;(b) checking each database can result in errors if the database is set to AutoClose.&lt;br&gt;&lt;br&gt;While (a) seems to have been fixed in SQL Server 2008 CU3 (see &lt;a href="http://support.microsoft.com/kb/958760/" title="http://support.microsoft.com/kb/958760/" target="_blank"&gt;http://support.microsoft.com/kb/958760/&lt;/a&gt;), (b) still seems to be a big issue for some customers.&amp;nbsp; For a lot more background information, see the following:&lt;br&gt;&lt;br&gt;&lt;a href="http://sqlblog.com/blogs/aaron_bertrand/archive/2008/07/07/a-little-management-studio-oops.aspx" title="http://sqlblog.com/blogs/aaron_bertrand/archive/2008/07/07/a-little-management-studio-oops.aspx" target="_blank"&gt;http://sqlblog.com/blogs/aaron_bertrand/archive/2008/07/07/a-little-management-studio-oops.aspx&lt;/a&gt;&lt;br&gt;&lt;br&gt;&lt;a href="http://connect.microsoft.com/SQL/feedback/ViewFeedback.aspx?FeedbackID=355238" title="http://connect.microsoft.com/SQL/feedback/ViewFeedback.aspx?FeedbackID=355238" target="_blank"&gt;http://connect.microsoft.com/SQL/feedback/ViewFeedback.aspx?FeedbackID=355238&lt;/a&gt;&lt;br&gt;&lt;br&gt;There are some workarounds posted there that may help end users avoid the problem, but last night fellow MVP Erland Sommarskog reminded me that there is another possible solution from the provider end:&lt;br&gt;&lt;/p&gt;


&lt;table bgcolor="#eeeeee" cellpadding="0" cellspacing="0"&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;pre style="padding:10px 20px;-moz-background-clip:border;-moz-background-origin:padding;font-size:12px;font-family:consolas,lucida console,courier new,courier;-moz-background-inline-policy:continuous;"&gt;&lt;font color="blue"&gt;DENY&amp;nbsp;VIEW&amp;nbsp;&lt;/font&gt;&lt;font color="gray"&gt;ANY&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;DATABASE&amp;nbsp;TO&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;[login]&lt;/font&gt;&lt;font color="gray"&gt;;&lt;br&gt;&lt;/font&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;

&lt;p&gt;This may not be appropriate in all situations, but in the hosted case where you have a mapping of one login to one database, it may be okay.&amp;nbsp; You can try this out in an isolated case using the following code: &lt;br&gt;&lt;/p&gt;
&lt;table bgcolor="#eeeeee" cellpadding="0" cellspacing="0"&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;pre style="padding:10px 20px;-moz-background-clip:border;-moz-background-origin:padding;font-size:12px;font-family:consolas,lucida console,courier new,courier;-moz-background-inline-policy:continuous;"&gt;&lt;font color="blue"&gt;USE&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;[master]&lt;/font&gt;&lt;font color="gray"&gt;;&lt;br&gt;&lt;/font&gt;&lt;font color="black"&gt;GO&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;CREATE&amp;nbsp;DATABASE&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;foo&lt;/font&gt;&lt;font color="gray"&gt;;&lt;br&gt;&lt;/font&gt;&lt;font color="black"&gt;GO&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;CREATE&amp;nbsp;DATABASE&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;bar&lt;/font&gt;&lt;font color="gray"&gt;;&lt;br&gt;&lt;/font&gt;&lt;font color="black"&gt;GO&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;CREATE&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;LOGIN&amp;nbsp;[foo]&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;WITH&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;PASSWORD&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;=&amp;nbsp;&lt;/font&gt;&lt;font color="red"&gt;N'foo'&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;DEFAULT_DATABASE&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;=&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;[foo]&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;CHECK_EXPIRATION&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;=&amp;nbsp;OFF&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;CHECK_POLICY&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;=&amp;nbsp;OFF&lt;/font&gt;&lt;font color="gray"&gt;;&lt;br&gt;&lt;/font&gt;&lt;font color="black"&gt;GO&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;CREATE&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;LOGIN&amp;nbsp;[bar]&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;WITH&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;PASSWORD&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;=&amp;nbsp;&lt;/font&gt;&lt;font color="red"&gt;N'bar'&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;DEFAULT_DATABASE&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;=&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;[bar]&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;CHECK_EXPIRATION&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;=&amp;nbsp;OFF&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;CHECK_POLICY&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;=&amp;nbsp;OFF&lt;/font&gt;&lt;font color="gray"&gt;;&lt;br&gt;&lt;/font&gt;&lt;font color="black"&gt;GO&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;USE&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;[foo]&lt;/font&gt;&lt;font color="gray"&gt;;&lt;br&gt;&lt;/font&gt;&lt;font color="black"&gt;GO&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;CREATE&amp;nbsp;&lt;/font&gt;&lt;font color="magenta"&gt;USER&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;[foo]&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;FOR&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;LOGIN&amp;nbsp;[foo]&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;WITH&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;DEFAULT_SCHEMA&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;=&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;[dbo]&lt;/font&gt;&lt;font color="gray"&gt;;&lt;br&gt;&lt;/font&gt;&lt;font color="black"&gt;GO&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;USE&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;[bar]&lt;/font&gt;&lt;font color="gray"&gt;;&lt;br&gt;&lt;/font&gt;&lt;font color="black"&gt;GO&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;CREATE&amp;nbsp;&lt;/font&gt;&lt;font color="magenta"&gt;USER&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;[bar]&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;FOR&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;LOGIN&amp;nbsp;[bar]&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;WITH&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;DEFAULT_SCHEMA&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;=&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;[dbo]&lt;/font&gt;&lt;font color="gray"&gt;;&lt;br&gt;&lt;/font&gt;&lt;font color="black"&gt;GO&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;USE&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;[master]&lt;/font&gt;&lt;font color="gray"&gt;;&lt;br&gt;&lt;/font&gt;&lt;font color="black"&gt;GO&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;DENY&amp;nbsp;VIEW&amp;nbsp;&lt;/font&gt;&lt;font color="gray"&gt;ANY&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;DATABASE&amp;nbsp;TO&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;[foo]&lt;/font&gt;&lt;font color="gray"&gt;;&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;DENY&amp;nbsp;VIEW&amp;nbsp;&lt;/font&gt;&lt;font color="gray"&gt;ANY&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;DATABASE&amp;nbsp;TO&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;[bar]&lt;/font&gt;&lt;font color="gray"&gt;;&lt;br&gt;&lt;/font&gt;&lt;font color="black"&gt;GO&lt;/font&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;


&lt;p&gt;The good news: if you connect as foo, you will not be able to see the bar database, and if you connect as bar, you will not be able to see the foo database.&amp;nbsp; The bad news: you also won't be able to see your own database in Object Explorer, because the DENY VIEW setting prevents the check that would bypass the restriction for the databases you own.&amp;nbsp; The screen shot below demonstrates that you login foo can see the databases foo, master and tempdb in sys.databases and in the query editor's database drop-down.&amp;nbsp; However, foo cannot see the foo database in Object Explorer.&lt;br&gt;&lt;br&gt;&lt;img src="http://sqlblog.com/blogs/aaron_bertrand/attachment/15339.ashx" border="1" height="212" width="560"&gt;&lt;br&gt;&lt;br&gt;This is certainly a bug and was reported way back:&lt;br&gt;&lt;br&gt;&lt;a href="http://connect.microsoft.com/SQL/feedback/ViewFeedback.aspx?FeedbackID=124651" title="http://connect.microsoft.com/SQL/feedback/ViewFeedback.aspx?FeedbackID=124651" target="_blank"&gt;http://connect.microsoft.com/SQL/feedback/ViewFeedback.aspx?FeedbackID=124651&lt;/a&gt;&lt;br&gt;&lt;br&gt;Since the database will not show up in Object Explorer, there are many things the end user won't be allowed to do (such as right-clicking the database and viewing properties, expanding lists of objects, etc.), but this *will* allow them to run queries against their own database from a query window (as long as their default database is not set to a database where they don't have permissions).&amp;nbsp; So, this could be a solution that is valuable for the hosted scenario, where you want to minimize the chance for errors, or where you simply don't want your customers to know how many databases are on your server or who those customers are.&amp;nbsp; Just be sure that your customers understand that they won't be able to use Object Explorer until this bug is fixed.&lt;/p&gt;
&lt;p&gt;As a few people have noted, you could get around this by making the login the owner of the database.&amp;nbsp; This may not always be possible in the hosted scenario, but once they brought it up I thought it was important to mention.&amp;nbsp; If you have created the above database as scripted, you can test this change as follows:&lt;/p&gt;

&lt;table bgcolor="#eeeeee" cellpadding="0" cellspacing="0"&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;pre style="padding:10px 20px;-moz-background-clip:border;-moz-background-origin:padding;font-size:12px;font-family:consolas,lucida console,courier new,courier;-moz-background-inline-policy:continuous;"&gt;&lt;font color="blue"&gt;USE&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;foo&lt;/font&gt;&lt;font color="gray"&gt;;&lt;br&gt;&lt;/font&gt;&lt;font color="black"&gt;GO&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;DROP&amp;nbsp;&lt;/font&gt;&lt;font color="magenta"&gt;USER&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;foo&lt;/font&gt;&lt;font color="gray"&gt;;&lt;br&gt;&lt;/font&gt;&lt;font color="black"&gt;GO&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;USE&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;bar&lt;/font&gt;&lt;font color="gray"&gt;;&lt;br&gt;&lt;/font&gt;&lt;font color="black"&gt;GO&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;DROP&amp;nbsp;&lt;/font&gt;&lt;font color="magenta"&gt;USER&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;bar&lt;/font&gt;&lt;font color="gray"&gt;;&lt;br&gt;&lt;/font&gt;&lt;font color="black"&gt;GO&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;USE&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;[master]&lt;/font&gt;&lt;font color="gray"&gt;;&lt;br&gt;&lt;/font&gt;&lt;font color="black"&gt;GO&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;ALTER&amp;nbsp;AUTHORIZATION&amp;nbsp;ON&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;DATABASE::foo&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;TO&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;[foo]&lt;/font&gt;&lt;font color="gray"&gt;;&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;ALTER&amp;nbsp;AUTHORIZATION&amp;nbsp;ON&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;DATABASE::bar&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;TO&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;[bar]&lt;/font&gt;&lt;font color="gray"&gt;;&lt;br&gt;&lt;/font&gt;&lt;font color="black"&gt;GO&lt;/font&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;

&lt;p&gt;Now when you connect via Object Explorer, as expected, you will be able to see *your* database(s) in the list. &lt;br&gt;&lt;/p&gt;
&lt;p&gt;Erland's suggestion is to add VIEW DEFINITION permissions per database, allowing you to customize database access at a higher level.&amp;nbsp; This is certainly a better way to do it, and they are hopefully going to look at it for the next version of SQL Server:&lt;br&gt;&lt;br&gt;&lt;a href="http://connect.microsoft.com/SQL/feedback/ViewFeedback.aspx?FeedbackID=273830" title="http://connect.microsoft.com/SQL/feedback/ViewFeedback.aspx?FeedbackID=273830" target="_blank"&gt;http://connect.microsoft.com/SQL/feedback/ViewFeedback.aspx?FeedbackID=273830&lt;/a&gt;
&lt;/p&gt;

&lt;p&gt;Finally, Steve Kass made a casual suggestion to name the databases differently: instead of naming my database "aaronbertrand.com" they could use a GUID for the name (and I would simply change my connection strings to point to the GUID as the database name).&amp;nbsp; While this doesn't hide the number of databases on the server, and arguably makes technical support and troubleshooting at least one step more complicated, it can certainly obscure customers' names from each other.&amp;nbsp; (As long as you don't expose the mapping of database name &amp;lt;-&amp;gt; GUID anywhere that your customers can get to, since support will need to perform this translation quite often.)&amp;nbsp; I would suggest using NEWID() and not NEWSEQUENTIALID() if you are going to go this route, because my database name of [C08CD...] is going to be easier to spot in a list or drop-down if there aren't 400 other similarly-named databases on the server.&amp;nbsp; And you will want to eliminate the dashes and skip any NEWID() values that are generated with a leading digit, as these will be problematic as identifiers.&lt;br&gt;&lt;/p&gt;</description></item></channel></rss>