Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Visual Studio "Access is denied"

Author  Topic 

nmarks
Yak Posting Veteran

53 Posts

Posted - 2011-07-05 : 03:43:49
Hello,

I am new to this so please go gently.

I have installed Visual Studio 2010, SQL Server Express and SSMS 2008 R2 on my machine.

In SSMS I have created a database with a single table and then closed SSMS.

In Visual Studio I have created an ASP.NET website and created a connection to that database using Server Explorer.

In the Solution Explorer I have right clicked the App Data and clicked Add Existing Item and selected that database.

I keep getting the error message "file already in use" even though no application is running with that file open.

I have disconnected the database in Server Explorer and still get the error message.

I have tried running Visual Studio as an adminstrator and get similar error messages.

I don't know why this should be happening or how to fix it. Please help.

Is there some other setting I need to check to enable the database to be added to my AppData folder in Visual Studio?

Is it wrong to have a connection to a database open and then try to include it in your AppData file?

Why can't I add that database to my AppData if i disconnect it?

All constructive replies are welcome.

It seems that:
(1) I cannot use SSMS to edit an SQL Server database that I created in VS2010 Soluation Explorer and
(2) I cannot attach an existing SQL Server database in VS2010 that I created in SSMS

lappin
Posting Yak Master

182 Posts

Posted - 2011-07-05 : 05:32:56
No need for this stage:
"In the Solution Explorer I have right clicked the App Data and clicked Add Existing Item and selected that database"
Create a connection string in web.config and reference this in your webpage to connect to the database. Connect either with trusted connection (windows user) or a SQL Account, e.g:
<connectionStrings>
<add name="DBNameConnectionString" connectionString="Data Source=xxx.xxx.xx.xxx;Initial Catalog=DBName;Persist Security Info=True;User ID=DBUser;Password=xxx" providerName="System.Data.SqlClient"/>
</connectionStrings>

then use "DBNameConnectionString" in webpage
Go to Top of Page

nmarks
Yak Posting Veteran

53 Posts

Posted - 2011-07-05 : 07:26:19
This problem has now been fixed.

Essentially I discovered that by default VS2010 is set up to save SQL server database it creates in the same folder as your project folder : by default this is set up as C:\Users\[used id]\Documents\Visual Studio 2010

SSMS cannot access this folder.

To prevent this problem I created a new folder in C: and save my projects there.

Solved.

(lappin: thanks for your reply).
Go to Top of Page
   

- Advertisement -