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

问题描述

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



我有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.

推荐答案


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

10-12 13:55