LocalDB deploy issue

时间:2015-06-30 13:36:54

标签: .net localdb

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.

1 个答案:

答案 0 :(得分:1)

运行应用程序的用户可能无权访问LocalDB默认实例(LocalDB)\v11使用的文件夹。 您可以先尝试创建自己的实例,然后使用它来创建新数据库。

从命令行调用SqlLocalDB utility

  1. sqllocaldb create "MY_INSTANCE" -s
  2. 在连接字符串中使用Data Source=(LocalDB)\MY_INSTANCE
  3. 使用C#代码和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
    }