Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 921
Pare Avatar asked Apr 10 '13 01:04

Pare


People also ask

How can I access one SQL Server database from another?

Start the SQL Server, in the dialog window for the Server name enters the name of the instance that you want to connect with. From the Authentication drop down box, select the SQL Server Authentication and for the field Login and the Password enter your credentials then click the Connect button.

How do I connect to LocalDB in SQL?

In the Command Prompt window, type the following command: SqlLocalDB create NewInstance and press the Enter key. The message will appear which indicates that the LocalDB instance is created: LocalDB instance “NewInstance” created with version 13.0. 2186.6.

Can I use LocalDB in production?

Despite their differences, Microsoft still allows both to be used for production applications at no cost. LocalDB can act as an embedded database for a small application and SQL Server Express can act as a more robust, full-featured remote database engine for larger applications.

Where is LocalDB stored?

Once installed, LocalDB is an instance of SQL Server Express that can create and open SQL Server databases. The system database files for the database are stored in the local AppData path, which is normally hidden.


1 Answers

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.

like image 153
Martin Costello Avatar answered Sep 17 '22 20:09

Martin Costello