次の方法で共有


.NET Framework 4 now supports LocalDB!

Updated 2011-11-11: Added a link to the post on how LocalDB handles database file locations.

Updated 2012-01-03: Clarified that only SSMS from SQL Server 2012 (or newer) will work with the .NET 4 Update 4.0.2, since earlier SSMS versions are using .NET 3.5.

.NET Framework 4 Update 4.0.2

.NET team has just released Update 4.0.2 for .NET Framework 4. This update enables connecting to SQL Server Express LocalDB via System.Data.SqlClient provider.

.NET Framework 4 Update 4.0.2 can be downloaded from https://support.microsoft.com/kb/2544514

Does this work?

Well, let's give it a try!

We start by installing SQL Server 2012 Management Studio RC0 (SSMS) and LocalDB together with .NET 4. The version of SSMS is important as earlier versions are using .NET 3.5 and currently only .NET 4 can be updated to understand LocalDB connection strings. Next we update .NET 4 to 4.0.2 (hey, no reboot in my case!). Then fire up SSMS. When prompted for the server address we specify " (localdb)\v11.0", like this:

Clicking Connect and … (drum roll please!) …

Success!

Does it really work?

OK, so we confirmed SSMS connects to LocalDB. Which is great, but how about doing something more useful for a developer? The next logical step would be to create a database. We know the drill -- right-click the Databases node in Object Explorer and select New Database. So far, so good. After typing in the name of the new database (in my case LocalDBTest) we are ready to hit OK...

Clicking OK and ... we hit an error!

 

This is obviously a bug, but there are at least two reasons we shouldn't panic. First, the bug has an easy workaround that we're going to use very, very soon. Second, it points to an important characteristic of the way LocalDB handles database files. I will explain it in more detail in the next post, but for now let's get back to LocalDB and creating our database.

To work around this problem we need to explicitly specify the folder for the database files. For the lack of a better location let's just put them into My Documents, like this:

This time clicking OK creates the database without any problems.

We are now ready for some serious database development, but this too will have to wait for another post.

- Krzysztof Kozielczyk

Send us Your Feedback

Please share your feedback with us! Feel free to start a thread on SQL Express Forum, hit the "Email Author" button on this post or file a Connect item!

Comments

  • Anonymous
    November 17, 2011
    Clear and useful article. Thanks for it. But sorry for you, i will wait for the official release of SQL Server 2012 ) to test it ( with an Express and Developer edition ). I am surprised because no reboot is necessary .Good news but when i will install .NET Framework 4 Update 4.0.2 , i think i will do a reboot ( as a precaution only )

  • Anonymous
    December 15, 2011
    The comment has been removed

  • Anonymous
    January 27, 2012
    Could you please leave the link to download SSMS as well ?

  • Anonymous
    January 30, 2012
    @ James William At this moment (January 2012), SQL Server 2012 Management Studio RC0 can be downloaded from here: www.microsoft.com/.../default.aspx Just select it from the drop-down list and click "Download". The page will probably disappear as soon as SQL Server 2012 is released, which is expected as you should use the RTM version at that time :-) Thanks,

  • Krzysztof
  • Anonymous
    February 16, 2012
    Hi, I updated to: .NET Framework 4 Update 4.0.2 can be downloaded from support.microsoft.com/.../2544514 and after that Visual Studio started to get painfully slow. Also I noticed a performance drop in ADO.Net communication. Problem was still there after reboot. The same code running on a computer without the update doesn't have that problem. Don't know if it's a coincidence but it didn't feel like it. Messed up the computer while uninstalling so I ended up in complete reinstall. And with everything in place except the update above, everything works again. //Daniel

  • Anonymous
    February 21, 2012
    @Daniel, We have not seen any other reports of ADO.NET performance problems caused by .NET Update 4.0.2. ADO.NET team is very interested in learning more about this case. If you have more details that could help us investigate further, could you please contact us directly by clicking the Email Author button? Thanks,

  • Krzysztof
  • Anonymous
    June 11, 2012
    The comment has been removed

  • Anonymous
    June 11, 2012
    Yes, you do need to ensure that the instance is running using the LocalDBStartInstance API call. And yes, this is currently available only as a C++ library.

  • Anonymous
    August 28, 2012
    The create database bug you describe is still present in the RTM version.

  • Anonymous
    August 30, 2012
    Yes Jon: unfortunately, this is true for RTM. It will be fixed in Service Pack 1 for SQL Server 2012. Until then, you need to use the workaround described in the original post.

  • Anonymous
    October 17, 2013
    While i am running on application,at the time i got following error.. A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server).what can i do.? what's the solution for that error.?

  • Anonymous
    July 01, 2014
    Referenced here from a question on stackoverflow. I am using SSMS 2008 R2 SP2 on my developer machine and i am able to connect to the localdb server using servername: (localdb)v11.0. Could there have been some update to the .Net framework 3.5 that allows the connection using this servername? I can't find any info about this using google. I Also get an error when using a non developer machine.