user3924088
user3924088

Reputation: 1

LocalDB deploy issue

Working on a VB.NET project with SQL Server LocalDB I'm having this problem:

When deploying on a client machine (Windows 7), my application tries to create a database on disk but it got ERROR 5 (Access denied)... (it seems SQLLocalDB does not have write permissions on disk)

It suppose I have not chance to manipulate that machine. I just send a SETUP that contains the program and SQLLocalDB as prerequisite.

How can I solve this issue from code since I cannot access to client machine?

Thanks.

Upvotes: 0

Views: 188

Answers (1)

igolaizola
igolaizola

Reputation: 71

The user running your application might not have access to the folder used by LocalDB default instance (LocalDB)\v11. You could try creating your own instance first and using it to create your new database.

Calling SqlLocalDB utility from command line:

  1. sqllocaldb create "MY_INSTANCE" -s
  2. Use Data Source=(LocalDB)\MY_INSTANCE within your connection strings.

Using C# code and SQL LocalDB Wrapper library:

ISqlLocalDbProvider provider = new SqlLocalDbProvider();
ISqlLocalDbInstance instance = provider.GetOrCreateInstance("MY_INSTANCE");
instance.Start();
using (SqlConnection connection = instance.CreateConnection())
{
   connection.Open();
   // Create here your database
}

Upvotes: 1

Related Questions