简体   繁体   中英

LightSwitch build fails using SQL Server 2014 LocalDB and Visual Studio 2013

I have SQL Server 2014 installed and want to use localdb\\v12.0 in Visual Studio. I found this post and understand how to connect to localdb using SQL Server Object Explorer successfully. Now I have created a LightSwitch project in Visual Studio 2013 and when building it throws exception:

An error occured while establishing a connection to SQL Server instance '(LocalDB)\\v11.0'.

Seems it is looking for SQL Server 2012 to create the development database in Bin\\Data and I don't have SQL Server 2012 so there is no localdb\\v11.0 on the system. So

  1. Why does VS 2013 try to use localdb\\v11.0 ?

  2. How can I force Visual Studio to use localdb\\v12.0 when building the project?

I tried changing the _IntrinsicData connection string in web.config but when building again it throws the same exception trying to use localdb\\v11.0 which belongs to SQL Server 2012!

Ok after spending lots of time I found what was the problem! Here is the cause and solution:

LightSwitch uses SQL Express LocalDB to store information such as User and Roles when building the project (this is called development database). There is no problem with SQL Server 2012 but if SQL Server 2014 is installed something force the LightSwitch to connect to (localdb)\\v11.0 . LightSwitch makes three projects in the solution. If the Client and the Server projects build successfully so the problem is with the third project. Go through these steps:

  1. Right-Click on the third project in the solution
  2. Select Unload Project
  3. Again Right-Click on it and select Edit <yourProjectName>.lsxtproj
  4. Search the SqlExpressInstancename
  5. You will find its value is (localDB)\\v11.0 !
  6. Change it to the right SQL Server LocalDB instance name; for more information check the notes below

在此处输入图片说明

Now the solution successfully build

--

Note 1: To see which version of SQL Server LocalDb is installed, open cmd and type sqllocaldb.exe v

Note 2: To which instance of LocalDb has been created on the system, open cmd and type sqllocaldb.exe info

Note 3: The instance which is going to be used by LightSwitch must be started: open cmd and type sqllocaldb.exe start


UPDATE: Looking for a better solution I found the correct way to fix this problem. It was a pain for me to follow those 6 steps every time I create a new LightSwitch project. So if you want to fix it once you can do it this way:

  1. In Visual Studio go to Tools->Options
  2. In the Database Tools select the Data Connections
  3. Set your desired SQL Server Instance Name

在此处输入图片说明

So no need to set it every time you create a LS project

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM