这个错误让我头疼 [英] This error put headache in my head

查看:82
本文介绍了这个错误让我头疼的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个错误让我困扰了很多天。请解决我最头疼的问题。



我有Database1.mdf进入解决方案资源管理器。我想在本地打开这个数据库到我的应用程序中。我使用下面的连接字符串,但它们中的任何一个都不起作用。



This error has stuck me for many days. Please solve end my this headache.

I have Database1.mdf into solution explorer. I want to open this database locally into my application. I used below connection strings but any of them is not working.

Dim cons As String
     'cons = "Server = .\ SQLExpress;AttachDbFilename=" & Application.StartupPath & "\Database1.mdf;Database=Database1;Trusted_Connection = Yes;"
     'cons = "Server=(localdb)\v11.0;Integrated Security=true;"
     cons = "Server = .\ SQLExpress;AttachDbFilename=|DataDirectory|Database1.mdf;Database=Database1;Trusted_Connection = Yes;"
     'cons = "Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\Database1.mdf;Integrated Security=True;Connect Timeout=30"
     'cons = "Server=(localdb)\v11.0;Integrated Security=true;AttachDbFileName=" & Application.StartupPath & "\Database1.mdf;"
     DbLib.GridViewQuery(Me.dgv, "Select * from Table1", cons)





它是给我这个错误。



附加信息:目录查找文件C:\ Users \ Rizwan Chattha \\ \\Documents\Visual Studio 2015 \Projects\TestDb\TestDb\bin \Debug \Database1.mdf因操作系统错误5失败(访问被拒绝。)。



无法附加文件'C:\ Users \ Rizwan Chattha \Documents\Visual Studio 2015 \Projects \TestDb \ TestDb \ bin \Debug \Database1.mdf '作为数据库'Database1'。





请指导我如何解决这个问题。



It is giving me this error.

Additional information: Directory lookup for the file "C:\Users\Rizwan Chattha\Documents\Visual Studio 2015\Projects\TestDb\TestDb\bin\Debug\Database1.mdf" failed with the operating system error 5(Access is denied.).

Cannot attach the file 'C:\Users\Rizwan Chattha\Documents\Visual Studio 2015\Projects\TestDb\TestDb\bin\Debug\Database1.mdf' as database 'Database1'.


Please guide me how to solve this problem.

推荐答案

用于运行SQL Server服务的帐户很可能没有mdf所在文件夹的权限(... \\\\Debug \)。



一种选择是检查和修改文件夹安全设置,或者将数据库文件的位置更改为SQL帐户具有权限的文件夹。我相信后者将是一个很好的选择。
Most likely the account that is used to run the SQL Server service does not have permission to the folder where the mdf is located (...\bin\Debug\).

One option is to check and modify the folder security settings or to change the location of the database file to such folder where the SQL account has permissions. I believe the latter would be a good choice to start with.


这篇关于这个错误让我头疼的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆