Sunday, March 3, 2013

Upgrading a SQL Server Database File

If you have a Visual Basic or C# application that connected to a database file created under Visual Studio 2010, you may have noticed that Visual Studio will not let you open or browse the database using Visual Studio 2012 tools. In addition, this is the new required connection string for the LocalDB server in Visual Studio 2012, shown here for the Karate database used in our books:

Data Source=(LocalDB)\v11.0;
AttachDbFilename=|DataDirectory|\karate.mdf;
Integrated Security=True;Connect Timeout=30

Here's how to use Visual Studio 2012 to upgrade a database file from SQL 2008 Express to LocalDB (SQL 2012) version. Follow these steps:

1. In Solution Explorer, double-click the database filename. This will cause a following dialog window to appear saying that the database file is not compatible with the current instance of SQL Server. When you click the OK button to close this dialog, the database filename will appear in the Server Explorer window.
 
2. Right-click the filename in Server Explorer and select Modify Connection.
 
3. In the Modify Connection window, click the Advanced button.
 
4. In the Advanced Properties window, select (LocalDB)\v11.0 for the Data Source, and set User Instance to False. Then click the OK button.
 
5. When a dialog window confirms that you want to upgrade the database file, click the Yes button.
 
The database is now upgraded. In the future, if you want to confirm that a database has been upgraded, right-click its name in Server Explorer and select Properties. Look for the Version property, which should equal 11.00 or later.
If you want to see a more visual version of this tutorial, go to https://dl.dropbox.com/u/24290605/blog_examples/Upgrading_database.htm
Enjoy!
--Kip Irvine