-1

I am unable to connect to a local SQL Server 2008 R2 trial version from Visual Studio 2010 Express.

When adding a new connection, I browse to the database file in this location:C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS\MSSQL\DATA\AdventureWorks_Data.mdf, I encounter this error:

Could not open new data base 'C:\PROGRAM FILES\MICROSOFT SQL SERVER\MSSQL10_50.SQLEXPRESS\MSSQL\DATA ADVENTUREWORKS_DATA.MDF'.CREATE DATABASE is aborted. An attempt to attach an auto-named database for file C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS\MSSQL\DATA AdventureWorks_Data.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share. File activation failure.The physical file name "C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS\MSSQL\DATA\AdventureWorks_Data_log.ldf" may be incorrect. The log cannot be rebuilt when the primary file is read-only.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
user1220000
  • 203
  • 1
  • 3
  • 6
  • 2
    just a wild guess - i think you are getting an error because your setting up a connection using an attached database that is already loaded in SQL Server. Try this: When adding the new connection via visual studio, on the first screen where you select a data source, choose `Microsoft SQL Server` instead of `Microsoft SQL Server Database File` – J Cooper Feb 20 '12 at 02:10
  • Thanks heaps for your answer. I did load the database file into SQL Server. On the visual studio when adding data source I have only 3 choices: Microsoft access database file, Microsoft SQL Server Compact 3.5 and Microsoft SQL Server Database File. – user1220000 Feb 21 '12 at 04:51
  • Thanks heaps for your answer. I did load the database file into SQL Server. On the visual studio when adding data source I have only 3 choices: Microsoft access database file, Microsoft SQL Server Compact 3.5 and Microsoft SQL Server Database File. The data provider is .Net Framework Data Provider for SQL Server. – user1220000 Feb 21 '12 at 04:59
  • Here is a link that i think describes your problem: http://stackoverflow.com/questions/9107566/add-sql-server-data-connection-in-visual-studio – J Cooper Feb 21 '12 at 05:07

1 Answers1

0

Another guess, you don't by any random chance have another user logged into the same machine that would have the DB file locked by connecting to it in the same way you say you're trying to? I'd imagine the previous comment about that database file already being attached to by the sql service is probably far far more likely, but just for wild chance I'm leaving my idea here for you or anyone else who happens by

maxx233
  • 108
  • 8
  • Thanks for your answer. I am the only user of my pc. – user1220000 Feb 21 '12 at 04:42
  • No worries. Did you understand J Cooper's comment above? That's very likely the solution - the sql service instance has the file locked rather than another user. So instead of trying to attach to the file, connect to the sql server instance that's already attached to the file. – maxx233 Feb 21 '12 at 04:47