How to share SQL LocalDb with other users on same machine?

Pare picture Pare · Apr 10, 2013 · Viewed 14k times · Source

I am looking for ways to access LocalDb database between users using the share command of sqllocaldb command utility but I cannot see the database created in one user in another.

Here are my steps:

  1. Login to user User1 on Windows 7

  2. Create a new database called test using sqlcmd as follows

    sqlcmd -S (localdb)\v11.0 create database test

  3. Share the instance v11.0 as follows with User2

    sqllocaldb share domain\User2 v11.0 myinstance

  4. Switch to User 2

  5. Login to shared instance as follows

    sqlcmd -S (localdb)\.\myinstance

    select name from sys.master_files

    The above query does not display test database.

Why am I not able to see the databases in User 2 that was created in User1 after sharing?

I thought it must work based on blog (approach 2)http://blogs.msdn.com/b/sqlexpress/archive/2011/12/09/using-localdb-with-full-iis-part-2-instance-ownership.aspx#SharedLocalDB by Krzysztof Kozielczyk but it does not.

Any help/suggestion is appreciated.

Thanks Pare

Answer

Martin Costello picture Martin Costello · Mar 19, 2014

The reason this isn't working is because you're issuing the wrong command. The usage instructions from sqllocaldb.exe are:

share|h ["owner SID or account"] "private name" "shared name"

Based on this, your second command should be the SID or account that created the instance, not with the account you want to share the instance with. Sharing shares an instance with all accounts on the machine.

Assuming that your account created the instance you want to share, then the command you should issue is:

sqllocaldb share v11.0 myinstance

Otherwise, it should be:

sqllocaldb share "<account that created the instance>" v11.0 myinstance

In either case, you also need to ensure that you are running an elevated command window so it can be successfully shared.