How do I connect to an older sql database using LocalDb in VS 2012?
Asked Answered
S

5

24

I am trying to construct a connection string to a 2008 SQL Express database file in VS 2012. I am getting an error dialog:

This database file is not compatible with the current instance of SQL Server. To resolve this issue, you must upgrade the database file by creating a new data connection, or you must modify the existing connection to this database file. For more information, see http://go.microsoft.com/fwlink/?LinkId=235986

I followed the link to Microsoft's always wonderfully helpful documentation (cough, cough..). When I went through the upgrade database function, I was not presented with a prompt to upgrade the file. I was really hoping to use LocalDb instead of having to do a install of SQL Express 2008. Any thoughts?

OTHER: Why hasn't Visual Studio implemented clicking on links in the error dialogs after all these years? Is it really hard to implement?

Shaffert answered 14/3, 2013 at 18:35 Comment(1)
I totally agree with you about not having a clickable link in the error dialog. It's frustrating, really! C'mon Microsoft... One has to type that link in the browser window. OMG.Mastersinger
M
24

From my experience of a few instants ago:

  1. Forget about trying to open the old SQL Server Express .mdf file in Visual Studio 2012. During the conversion process of an old VS 2010 solution to VS 2012 it tells you can do that by just double clicking the database file and upgrade it to use LocalDb instead. That's a complete lie! :D

  2. Open SQL Server Management Studio, select the Databases node, right click it and select Attach....

  3. Provide the path for the .mdf file, click OK and then you should be good to go.

  4. Now inside Visual Studio 2012, open Server Explorer (menu View -> Server Explorer), right click Data Connections and then select Add Connection.... In Server name: put (localdb)\v11.0 and in Connect to a database: select the database you attached previously.

  5. Right click the Data Connection just added in Solution Explorer and select Properties. Copy the Connection String property and replace the Web.Config or App.Config one with this value.

Note: In SQL Server Management Studio I got an error while trying to attach an old .mdf file I got from this sample project from DayPilot: Scheduler for ASP.NET MVC 4 Razor (C#, VB.NET, SQL Server). It was related to a path issue regarding the .log file that accompanies the .mdf database file. I just selected the .log file entry in the Attach... dialog window and removed it. Then tried to attach the database again and it worked.

Mastersinger answered 8/5, 2013 at 2:27 Comment(3)
This worked for me. I up-voted before even trying it when I read "That's a complete lie!". So true.Bosporus
This works also for Visual Studio 2013, for those wondering. Thank you!Irrawaddy
this is what I got when i went to download center. "We are sorry, the page you requested cannot be found."Daphne
L
53

my simple way:

  1. go to VisualStadio 2012
  2. In Server Explorer Windows
  3. open Data Connections
  4. Right click on ASPNETDB.MDF
  5. click on Modify Connection...
  6. a new windows open for you ... you just click OK
  7. if other windows open for you click Yes
  8. FINISH ( be Happy ) :D
Lettyletup answered 27/6, 2014 at 10:10 Comment(3)
You´re awesome buddy, many thanks! However, when I choose Tables-> Add New Table, nothing happens, do you know why?Cluster
I'm happy! Thank you!How
@Omid Finish (be Happy) :D - yes very happy indeed, thanks a millionChromatin
M
24

From my experience of a few instants ago:

  1. Forget about trying to open the old SQL Server Express .mdf file in Visual Studio 2012. During the conversion process of an old VS 2010 solution to VS 2012 it tells you can do that by just double clicking the database file and upgrade it to use LocalDb instead. That's a complete lie! :D

  2. Open SQL Server Management Studio, select the Databases node, right click it and select Attach....

  3. Provide the path for the .mdf file, click OK and then you should be good to go.

  4. Now inside Visual Studio 2012, open Server Explorer (menu View -> Server Explorer), right click Data Connections and then select Add Connection.... In Server name: put (localdb)\v11.0 and in Connect to a database: select the database you attached previously.

  5. Right click the Data Connection just added in Solution Explorer and select Properties. Copy the Connection String property and replace the Web.Config or App.Config one with this value.

Note: In SQL Server Management Studio I got an error while trying to attach an old .mdf file I got from this sample project from DayPilot: Scheduler for ASP.NET MVC 4 Razor (C#, VB.NET, SQL Server). It was related to a path issue regarding the .log file that accompanies the .mdf database file. I just selected the .log file entry in the Attach... dialog window and removed it. Then tried to attach the database again and it worked.

Mastersinger answered 8/5, 2013 at 2:27 Comment(3)
This worked for me. I up-voted before even trying it when I read "That's a complete lie!". So true.Bosporus
This works also for Visual Studio 2013, for those wondering. Thank you!Irrawaddy
this is what I got when i went to download center. "We are sorry, the page you requested cannot be found."Daphne
D
1

You can just do:

USE [master]
GO
CREATE DATABASE [database_name] ON 
    ( FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\Data\<database name>.mdf' ),
    ( FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\Data\<database name>.ldf' )
FOR ATTACH ;
GO

As described here: http://technet.microsoft.com/en-us/library/ms165673%28v=sql.105%29.aspx

Difficile answered 20/11, 2013 at 13:0 Comment(0)
T
0

go to VisualStadio 2012 In Server Explorer Windows open Data Connections Right click on ASPNETDB.MDF click on Modify Connection... a new windows open for you ... you just click OK if other windows open for you click Yes

Terracotta answered 23/1, 2017 at 11:3 Comment(0)
W
0

open sql server management studio connect localDB remove deattach same name mdf file then attach your mdf file

go to visual studio in server explorer-> dataconnection right click on your database -> modify connection -> text connection -> click OK

Wilheminawilhide answered 15/11, 2017 at 14:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.