如何将LocalDB添加到Visual Studio 2015社区的SQL Server对象浏览器中?

时间:2021-07-22 02:43:41

Problem

I don't understand how to make LocalDB show up in the SQL Server Object Explorer. On some VMs, it shows up automatically, on some other VMs, it doesn't. Still, after googling for hours, I don't get it.

我不知道如何使LocalDB显示在SQL Server对象浏览器中。在某些vm上,它会自动显示,在其他vm上,它不会。不过,在谷歌上搜索了几个小时后,我还是不明白。

Current situation

  1. I have a clean VM
  2. 我有一个干净的VM。
  3. I installed Visual Studio 2015 Community (all default settings)
  4. 我安装了Visual Studio 2015 Community(所有默认设置)
  5. I let a console application run (Entity Framework 6, code-first, console application) which worked on another VM and created a database automatically which then showed up in the SQL Server Object Explorer; but not this time
  6. 我让一个控制台应用程序运行(实体框架6,代码优先,控制台应用程序),它在另一个VM上工作并自动创建一个数据库,然后显示在SQL Server对象浏览器中;但不是这个时候

The error says:

这个错误表示:

System.Data.SqlClient.SqlException (0x80131904): 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: SQL Network Interfaces, error: 52 - Unable to locate a Local Database Runtime installation. Verify that SQL Server Express is properly installed and that the Local Database Runtime feature is enabled.) ---> System.ComponentModel.Win32Exception (0x80004005): The system cannot find the file specified

So, on this VM, no database gets created and nothing shows up in the SQL Server Object Explorer's SQL Server node.

因此,在这个VM上,不会创建任何数据库,也不会出现在SQL Server Object Explorer的SQL Server节点中。

如何将LocalDB添加到Visual Studio 2015社区的SQL Server对象浏览器中?

What I think to know

  • Visual Studio 2015 Community comes with LocalDB; so everything should just work out of the box, but it doesn't, and I don't know why
  • Visual Studio 2015 Community with LocalDB;所以所有的东西都应该是开箱即用的,但是没有,我不知道为什么
  • LocalDB databases are just a pair of files (*.mdf and *.ldf)
  • LocalDB数据库只是一对文件(*)。mdf和* .ldf)
  • I've seen the files being created at the default database location at C:\Users\<username>\AppData\Local\Microsoft\Microsoft SQL Server Local DB\Instances\MSSQLLocalDB; but on this VM, there is no such folder
  • 我看过的文件被创建在默认的数据库位置C:\Users\ <用户名> \ AppData \当地\微软\ Microsoft SQL Server数据库\ \ MSSQLLocalDB实例;但是在这个VM上,没有这样的文件夹。
  • The App.config looked every time like this (and it was automatically created that way when I installed Entity Framework 6 the NuGet Package Manager in Visual Studio:
  • 这个App.config每次看起来都是这个样子(当我在Visual Studio中安装了Entity Framework 6 NuGet Package Manager时,它是自动创建的):

App.config

<configuration>
  <configSections>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="mssqllocaldb" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
</configuration>

Other random comments

  • Earlier, with SQL Server, it was necessary to open up certain ports, but LocalDB runs, as I understand it, as a separate process on demand when started by Visual Studio.
  • 在前面的SQL Server中,有必要打开某些端口,但是据我理解,LocalDB在Visual Studio启动时作为一个独立的进程按需运行。
  • I don't know how to debug the SQLException
  • 我不知道如何调试SQLException异常
  • Does LocalDB not come packaged with Visual Studio 2015 Community and do I need to install it separately?
  • LocalDB是否没有与Visual Studio 2015 Community打包,我是否需要单独安装它?

7 个解决方案

#1


45  

I had the same issue today recently installing VS2015 Community Edition Update 1.

我今天遇到了同样的问题,最近安装了VS2015社区版更新1。

I fixed the problem by just adding the "SQL Server Data Tools" from the VS2015 setup installer... When I ran the installer the first time I selected the "Custom" installation type instead of the "Default". I wanted to see what install options were available but not select anything different than what was already ticked. My assumption was that whatever was already ticked was essentially the default install. But its not.

我通过添加VS2015安装程序中的“SQL Server数据工具”解决了这个问题。当我第一次运行安装程序时,我选择了“自定义”安装类型而不是“默认”安装类型。我想看看有哪些安装选项可用,但没有选择任何与已勾选的选项不同的内容。我的假设是,已经被勾选的内容本质上就是默认安装。但它不是。

#2


23  

To check if LocalDb is installed or not:

检查是否安装了LocalDb:

  • Run SSMS (SQL Server Management Studio).
  • 运行SSMS (SQL Server Management Studio)。
  • Try to connect to this instance (localdb)\V11.0 using windows authentication.
  • 尝试使用windows身份验证连接到这个实例(localdb)\V11.0。

If an error is raised Cannot connect to (localdb)\V11.0. change the instance name to (localdb)\MSSQLLocalDB and try again to connect, if you still get the same error.

如果出现错误,则无法连接到(localdb)\V11.0。将实例名更改为(localdb)\MSSQLLocalDB并尝试再次连接,如果您仍然得到相同的错误。

Follow these steps to install LocalDb:

按照以下步骤安装LocalDb:

  • Close SSMS.
  • 亲密的地对地导弹。
  • Close VS (Visual Studio) if it's running.
  • 关闭VS (Visual Studio),如果它正在运行。
  • Go to Start Menu and type in search sqlLocalDb.
  • 点击“开始”菜单,输入“搜索sqlLocalDb”。
  • From the results that appears choose sqlLocalDb.msi and click it.
  • 从显示的结果中选择sqlLocalDb。msi并单击它。
  • SQL setup will start to install LocalDB
  • SQL setup将开始安装LocalDB

after finishing the installation re-run SSMS and try connecting to either of the instances (localdb)\V11.0 or (localdb)\MSSQLLocalDB, one of it should work depending on what Visual Studio version you have.

安装完成后,重新运行SSMS,并尝试连接到实例(localdb)\V11.0或(localdb)\MSSQLLocalDB,其中一个应该可以根据您拥有的Visual Studio版本工作。

You can also verify that localdb is installed using Visual Studio by simply creating new sql file and go to the connect icon on the top header of the file which by default lists all the servers you can connect to including localdb if installed.

您还可以通过创建新的sql文件并切换到文件顶部头的connect图标来验证是否使用了Visual Studio安装localdb,该图标默认列出了您可以连接到的所有服务器,如果安装了的话,包括localdb。

In addition to the above mentioned ways of finding if localdb is installed, you can also use the MS windows power shell or windows command processor CMD or even NuGet package manager console on your server machine and run these commands sqllocaldb i and sqllocaldb v that will show you the localdb name if it is installed and the MSSQL server version installed and running on your machine.

除了上述的方法发现如果安装localdb,您还可以使用windows shell或命令处理器CMD女士甚至NuGet包管理器控制台服务器机器上运行这些命令sqllocaldb我和sqllocaldb v,将向您展示localdb名称如果是安装和该服务器版本安装和运行在您的机器上。

#3


14  

If you are not sure if local db is installed, or not sure which database name you should use to connect to it - try running 'sqllocaldb info' command - it will show you existing localdb databases.

如果您不确定是否安装了本地数据库,或者不确定应该使用哪个数据库名称来连接到它——请尝试运行“sqllocaldb info”命令——它将显示现有的localdb数据库。

Now, as far as I know, local db should be installed together with Visual Studio 2015. But probably it is not required feature, and if something goes wrong or it cannot be installed for some reason - Visual Studio installation continues still (note that is just my guess). So to be on the safe side don't rely on it will always be installed together with VS.

现在,据我所知,local db应该和Visual Studio 2015一起安装。但它可能不是必需的特性,如果出现问题或由于某种原因无法安装,那么Visual Studio仍然会继续安装(请注意,这只是我的猜测)。所以,为了安全起见,不要依赖它,它将永远与VS一起安装。

#4


8  

  1. Search "sqlLocalDb" from start menu,
  2. 从开始菜单中搜索“sqlLocalDb”,
  3. Click on the run command,
  4. 单击run命令,
  5. Go back to VS 2015 tools/connect to database,
  6. 回到VS 2015工具/连接数据库,
  7. select MSSQL server,
  8. 选择该服务器,
  9. enter (localdb)\MSSQLLocalDB as server name
  10. 输入(localdb)\MSSQLLocalDB作为服务器名。

Select your database and ready to go.

选择您的数据库并准备就绪。

#5


4  

I tried to install only LocalDB, which was missed in my VS 2015 installation. Followed below URL & selectively download the LocalDB (2012) installer which is only 33mb in size :)

我尝试只安装LocalDB,但是在我的VS 2015安装中没有安装。以下是URL并有选择地下载LocalDB(2012)安装程序,它的大小只有33mb:)

https://www.microsoft.com/en-us/download/details.aspx?id=29062

https://www.microsoft.com/en-us/download/details.aspx?id=29062

If you are looking for the SQL Server Data Tool for Visual Studio 2015 Integration, then Please download that from :

如果您正在寻找Visual Studio 2015集成的SQL Server数据工具,请从

https://msdn.microsoft.com/en-us/mt186501

https://msdn.microsoft.com/en-us/mt186501

#6


1  

  1. Search for sqllocaldb or localDB and right click on open file location
  2. 搜索sqllocaldb或localDB并右键单击打开的文件位置
  3. Open command prompt in the file location you found from the search
  4. 在搜索中找到的文件位置中打开命令提示符
  5. On your command prompt type sqllocaldb start

    在命令提示符上输入sqllocaldb启动

  6. Use <add name="defaultconnection" connectionString="Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=tododb;Integrated Security=True" providerName="System.Data.SqlClient" />

    使用

#7


0  

My App.config looks as below:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="v11.0" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
</configuration>

I noticed that there is localDB in the path that you mentioned above and has the version v11.0. So I entered (LocalDB\V11.0) in Add Connection dialogue and it worked for me.

我注意到前面提到的路径中有localDB,并且有v11.0版本。所以我在Add Connection对话中输入了(LocalDB\V11.0),它对我来说是有效的。

#1


45  

I had the same issue today recently installing VS2015 Community Edition Update 1.

我今天遇到了同样的问题,最近安装了VS2015社区版更新1。

I fixed the problem by just adding the "SQL Server Data Tools" from the VS2015 setup installer... When I ran the installer the first time I selected the "Custom" installation type instead of the "Default". I wanted to see what install options were available but not select anything different than what was already ticked. My assumption was that whatever was already ticked was essentially the default install. But its not.

我通过添加VS2015安装程序中的“SQL Server数据工具”解决了这个问题。当我第一次运行安装程序时,我选择了“自定义”安装类型而不是“默认”安装类型。我想看看有哪些安装选项可用,但没有选择任何与已勾选的选项不同的内容。我的假设是,已经被勾选的内容本质上就是默认安装。但它不是。

#2


23  

To check if LocalDb is installed or not:

检查是否安装了LocalDb:

  • Run SSMS (SQL Server Management Studio).
  • 运行SSMS (SQL Server Management Studio)。
  • Try to connect to this instance (localdb)\V11.0 using windows authentication.
  • 尝试使用windows身份验证连接到这个实例(localdb)\V11.0。

If an error is raised Cannot connect to (localdb)\V11.0. change the instance name to (localdb)\MSSQLLocalDB and try again to connect, if you still get the same error.

如果出现错误,则无法连接到(localdb)\V11.0。将实例名更改为(localdb)\MSSQLLocalDB并尝试再次连接,如果您仍然得到相同的错误。

Follow these steps to install LocalDb:

按照以下步骤安装LocalDb:

  • Close SSMS.
  • 亲密的地对地导弹。
  • Close VS (Visual Studio) if it's running.
  • 关闭VS (Visual Studio),如果它正在运行。
  • Go to Start Menu and type in search sqlLocalDb.
  • 点击“开始”菜单,输入“搜索sqlLocalDb”。
  • From the results that appears choose sqlLocalDb.msi and click it.
  • 从显示的结果中选择sqlLocalDb。msi并单击它。
  • SQL setup will start to install LocalDB
  • SQL setup将开始安装LocalDB

after finishing the installation re-run SSMS and try connecting to either of the instances (localdb)\V11.0 or (localdb)\MSSQLLocalDB, one of it should work depending on what Visual Studio version you have.

安装完成后,重新运行SSMS,并尝试连接到实例(localdb)\V11.0或(localdb)\MSSQLLocalDB,其中一个应该可以根据您拥有的Visual Studio版本工作。

You can also verify that localdb is installed using Visual Studio by simply creating new sql file and go to the connect icon on the top header of the file which by default lists all the servers you can connect to including localdb if installed.

您还可以通过创建新的sql文件并切换到文件顶部头的connect图标来验证是否使用了Visual Studio安装localdb,该图标默认列出了您可以连接到的所有服务器,如果安装了的话,包括localdb。

In addition to the above mentioned ways of finding if localdb is installed, you can also use the MS windows power shell or windows command processor CMD or even NuGet package manager console on your server machine and run these commands sqllocaldb i and sqllocaldb v that will show you the localdb name if it is installed and the MSSQL server version installed and running on your machine.

除了上述的方法发现如果安装localdb,您还可以使用windows shell或命令处理器CMD女士甚至NuGet包管理器控制台服务器机器上运行这些命令sqllocaldb我和sqllocaldb v,将向您展示localdb名称如果是安装和该服务器版本安装和运行在您的机器上。

#3


14  

If you are not sure if local db is installed, or not sure which database name you should use to connect to it - try running 'sqllocaldb info' command - it will show you existing localdb databases.

如果您不确定是否安装了本地数据库,或者不确定应该使用哪个数据库名称来连接到它——请尝试运行“sqllocaldb info”命令——它将显示现有的localdb数据库。

Now, as far as I know, local db should be installed together with Visual Studio 2015. But probably it is not required feature, and if something goes wrong or it cannot be installed for some reason - Visual Studio installation continues still (note that is just my guess). So to be on the safe side don't rely on it will always be installed together with VS.

现在,据我所知,local db应该和Visual Studio 2015一起安装。但它可能不是必需的特性,如果出现问题或由于某种原因无法安装,那么Visual Studio仍然会继续安装(请注意,这只是我的猜测)。所以,为了安全起见,不要依赖它,它将永远与VS一起安装。

#4


8  

  1. Search "sqlLocalDb" from start menu,
  2. 从开始菜单中搜索“sqlLocalDb”,
  3. Click on the run command,
  4. 单击run命令,
  5. Go back to VS 2015 tools/connect to database,
  6. 回到VS 2015工具/连接数据库,
  7. select MSSQL server,
  8. 选择该服务器,
  9. enter (localdb)\MSSQLLocalDB as server name
  10. 输入(localdb)\MSSQLLocalDB作为服务器名。

Select your database and ready to go.

选择您的数据库并准备就绪。

#5


4  

I tried to install only LocalDB, which was missed in my VS 2015 installation. Followed below URL & selectively download the LocalDB (2012) installer which is only 33mb in size :)

我尝试只安装LocalDB,但是在我的VS 2015安装中没有安装。以下是URL并有选择地下载LocalDB(2012)安装程序,它的大小只有33mb:)

https://www.microsoft.com/en-us/download/details.aspx?id=29062

https://www.microsoft.com/en-us/download/details.aspx?id=29062

If you are looking for the SQL Server Data Tool for Visual Studio 2015 Integration, then Please download that from :

如果您正在寻找Visual Studio 2015集成的SQL Server数据工具,请从

https://msdn.microsoft.com/en-us/mt186501

https://msdn.microsoft.com/en-us/mt186501

#6


1  

  1. Search for sqllocaldb or localDB and right click on open file location
  2. 搜索sqllocaldb或localDB并右键单击打开的文件位置
  3. Open command prompt in the file location you found from the search
  4. 在搜索中找到的文件位置中打开命令提示符
  5. On your command prompt type sqllocaldb start

    在命令提示符上输入sqllocaldb启动

  6. Use <add name="defaultconnection" connectionString="Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=tododb;Integrated Security=True" providerName="System.Data.SqlClient" />

    使用

#7


0  

My App.config looks as below:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="v11.0" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
</configuration>

I noticed that there is localDB in the path that you mentioned above and has the version v11.0. So I entered (LocalDB\V11.0) in Add Connection dialogue and it worked for me.

我注意到前面提到的路径中有localDB,并且有v11.0版本。所以我在Add Connection对话中输入了(LocalDB\V11.0),它对我来说是有效的。