0

When I open a visual studio 2010 solution with visual studio 2012 I get the following message:

SQL Server Express and LocalDB

In the Web.config file I changed the connectionstring

from:

connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename
=|DataDirectory|\databaseName.mdf;Integrated Security=True;User Instance=True"

to:

connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename
=|DataDirectory|\databaseName.mdf;Integrated Security=True"

I can't connect with the database and when I run the application I still get an error message:

An attempt to attach an auto-named database for file (FILE) failed. 
A database with the same name exists, or specified file cannot be opened, 
or it is located on UNC share.

The attempt to attach to the database failed with the following information: 
Failed to generate a user instance of SQL Server due to a failure in starting 
the process for the user instance. The connection will be closed.
Gilko
  • 2,280
  • 8
  • 36
  • 45
  • 1
    why are you changing the db connection string? just open the 2010 solution and VS will prompt you with any updates and make them automatically in web.config. Is your problem actually opening the solution or connecting to a different database? – Tanner Jul 26 '13 at 09:43
  • 1
    User Instance = True is missing on the second connection string – Steve Jul 26 '13 at 09:46
  • It isn't a problem to open the project with visual studio 2012, but how can I adjust the database (the mdf file) to work with VS 2012? – Gilko Jul 26 '13 at 09:54
  • @Tanner: The problem is connecting to a database. – Gilko Jul 26 '13 at 15:13

2 Answers2

0

Just double click on the solution of your project. And convert the project automatically.

  • And back it up when you do. Once it goes, it'll never come back. – ChiefTwoPencils Jul 26 '13 at 10:25
  • When I double click the solution I get this message: https://www.google.be/search?q=the+web+project+requires+sql+server+express&um=1&ie=UTF-8&hl=en&tbm=isch&source=og&sa=N&tab=wi&ei=ZmryUZ-4D827Pbz-gOgP&biw=1600&bih=738&sei=aGryUdOpD4bnOeu2gPAB#facrc=_&imgdii=_&imgrc=lA0dfsdmCoBFlM%3A%3B7G2IOajAu-F2dM%3Bhttp%253A%252F%252Fblog.redjungle.com%252Fimage.axd%253Fpicture%253Dimage_thumb_2.png%3Bhttp%253A%252F%252Fblog.redjungle.com%252Fpost%252F2013%252F02%252F05%252FTo-upgrade-the-project-database-to-use-SQL-Server-LocalDB-Express-Error-Dialog.aspx%3B511%3B299 – Gilko Jul 26 '13 at 12:24
  • @Gilko: but did you do what the message says to do? – ChiefTwoPencils Jul 26 '13 at 20:08
0

I have been able to connect to my database, but I still get an error message.

  • In server explorer (view > server explorer) click on the connect to database button.
  • Data Source: Microsoft SQL Server (SqlClient)
  • Server Name: (LocalDB)\v11.0
  • Attach a database file: path to mdf file
  • Test Connection
  • OK (if test connection succeeded)

After all these steps I have the green icon on my database icon in Server Explorer.

Now you can right click on database and choose properties, then you select the connectionstring and paste it in the Webconfig file.

When I press F5 on my Default.aspx file, I still get the error message:

Sql exception was unhandled by user code

An attempt to attach an auto-named database for file C:\(path to file) failed. 
A database with the same name exists, or specified file cannot be opened, 
or it is located on UNC share.

I get the error message in the file CategoriesBLL.cs at the line

return Adapter.GetCategories();
Gilko
  • 2,280
  • 8
  • 36
  • 45
  • If you have a new question, please ask it by clicking the [Ask Question](http://stackoverflow.com/questions/ask) button. Include a link to this question if it helps provide context. – SchmitzIT Apr 02 '14 at 10:35
  • Please use the edit link on your question to add additional information. The Post Answer button should be used only for complete answers to the question. – MarmiK Apr 02 '14 at 11:19