.NET

.NET Musings

Wandering thoughts of a developer, architect, speaker, and trainer

NAVIGATION - SEARCH

Fixing SQL Server Express Local DB for Visual Studio

LocalDB is a (fairly) new, stripped down version of SQL Express 2012.  It doesn’t require a service, so it can be deployed much easier along with your Visual Studio project.  It’s a great alternative for applications that don’t need all of the power of SQL Server, and where you don’t have control over the target machine to ensure that SQL Express is installed.  In fact, many of the samples available from Microsoft use LocalDB. Are you using LocalDB?  It’s easy to check.  If your connection string starts with “(LocalDB)\v11.0”, indeed you are.

Sounds great, doesn’t it?  Except when LocalDB doesn’t work.  I ran into this issue on my main development machine.  I tried reinstalling LocalDB (there is a separate install on the SQL Server Express download page), uninstalled SQL Express and reinstalled, you know, all of the usual tricks.  No luck.

After much searching on the interwebs, I found this TechNet forum post: http://social.technet.microsoft.com/Forums/sqlserver/en-US/8bcb5f1e-0240-4df3-8a5e-7e3e73e1c45b/cant-connect-to-localdb?forum=sqlexpress which pointed to this TechNet article: http://social.technet.microsoft.com/wiki/contents/articles/4609.troubleshoot-sql-server-2012-express-localdb.aspx

To sum it up, open a command window (preferably running as administrator), and navigate to where the LocalDB general instances are kept (%localappdata%\Microsoft\Microsoft SQL Server Local DB\Instances\v11.0), and type:

>sqllocaldb create "v11.0"

If you receive an error similar to this:

"Creation of LocalDB instance "v11.0" with version 11.0 failed because of the following error:
LocalDB instance is corrupted. See the Windows Application event log for event details."

Your LocalDb needs to be deleted and re-created.  Fortunately, it’s easy. Enter these commands:

>sqllocaldb delete "v11.0"
Response whould be similar to “LocalDB instance "v11.0" deleted. \”

Once you’ve cleaned out the corrupted instance, re-create it:

>sqllocaldb create "v11.0"
LocalDB instance "v11.0" created with version 11.0

And that’s it!  You should be able to fully take advantage of LocalDb in your projects now.

About the author

Philip Japikse

Philip Japikse Philip Japikse is an international speaker, a Microsoft MVP, INETA Community Champion, MCSD, CSM/ CSP, and a passionate member of the developer community, Phil has been working with .Net since the first betas, developing software for over 20 years, and heavily involved in the agile community since 2005. Phil works as a Principal Developer Advocate for Telerik. Phil co-hosts the Hallway Conversations podcast (http://www.hallwayconversations.com), and is the Lead Director for the Cincinnati .Net User’s Group (http://www.cinnug.org). You can follow Phil on twitter via www.twitter.com/skimedic read his Telerik blog at http://blogs.telerik.com/skimedic and his personal blog at www.skimedic.com/blog.
Managed Windows Shared Hosting by OrcsWeb