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.
答案 0 :(得分:1)
运行应用程序的用户可能无权访问LocalDB默认实例(LocalDB)\v11
使用的文件夹。
您可以先尝试创建自己的实例,然后使用它来创建新数据库。
从命令行调用SqlLocalDB utility:
sqllocaldb create "MY_INSTANCE" -s
Data Source=(LocalDB)\MY_INSTANCE
。使用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
}