I have a single-user Win Forms application that uses an SQL Server Express database via ADO.NET. I want to add more to my app, but by using Linq to Sql (while I learn Linq to Sql). I am unable to see the database in two places simultaneously. Either I can see it in the original code using ADO, or I can see it with the new code using Linq to SQL. Using the data with one method makes the other refuse to see it. Previously, I enabled the new Linq to SQL code to see it by copying the database's containing directory, with the database as well, to another directory name and getting at it with L2S before getting it with ADO. This allowed me to see that my Linq to SQL code worked (hooray!). However, now I can't use that new database with the original code with ADO because "Access is denied(5).". What am I doing wrong? How do I make it share?
我有一个单用户Win Forms应用程序,它通过ADO.NET使用SQL Server Express数据库。我想在我的应用程序中添加更多内容,但是使用Linq to Sql(我学习Linq to Sql)。我无法同时在两个地方看到数据库。我可以使用ADO在原始代码中看到它,或者我可以使用Linq to SQL使用新代码看到它。使用一种方法使用数据会让另一种方法拒绝看到它。以前,我启用了新的Linq to SQL代码,通过将数据库的包含目录(也包括数据库)复制到另一个目录名,然后使用L2S获取它,然后再使用ADO。这让我看到我的Linq to SQL代码工作了(万岁!)。但是,现在我无法使用带有ADO的原始代码的新数据库,因为“访问被拒绝(5)。”。我究竟做错了什么?我该如何分享?
EDIT: Removed the part of the question asking about attaching in SQL Server; that part of the problem is that I need to run SQL Server as an admin (Vista) and now it attaches. /EDIT
编辑:删除了有关在SQL Server中附加的问题的部分;问题的一部分是我需要以管理员(Vista)的身份运行SQL Server,现在它已经附加了。 /编辑
Now that I am using L2S, when I try to open the connection in ADO.NET, I get "Unable to open the physical file "C:\PRICINGtests\PRICING.MDF". Operating system error 5: "5(Access is denied.)". An attempt to attach an auto-named database for file C:\PRICINGtests\PRICING.MDF failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share."
现在我正在使用L2S,当我尝试在ADO.NET中打开连接时,我得到“无法打开物理文件”C:\ PRICINGtests \ PRICING.MDF“。操作系统错误5:”5(访问被拒绝。)“。尝试为文件C:\ PRICINGtests \ PRICING.MDF附加自动命名的数据库失败。存在具有相同名称的数据库,或者无法打开指定的文件,或者它位于UNC共享上。”
1 个解决方案
#1
Have you got two separate connection strings here? I presume you have and they're both trying to attach the mdf with the same database name on to your sql server which isn't allowed.
你有两个独立的连接字符串吗?我认为你有,并且他们都试图将具有相同数据库名称的mdf附加到不允许的sql server上。
Have you ADO & Linq code use the same single connection string and they'll both use the same database.
你有ADO和Linq代码使用相同的单个连接字符串,他们都使用相同的数据库。
#1
Have you got two separate connection strings here? I presume you have and they're both trying to attach the mdf with the same database name on to your sql server which isn't allowed.
你有两个独立的连接字符串吗?我认为你有,并且他们都试图将具有相同数据库名称的mdf附加到不允许的sql server上。
Have you ADO & Linq code use the same single connection string and they'll both use the same database.
你有ADO和Linq代码使用相同的单个连接字符串,他们都使用相同的数据库。