我无法在没有安装SqlServer Express的计算机上运行Sql Server localdb连接 [英] I can't get a Sql Server localdb connection to work on a computer that does not have SqlServer Express installed

查看:767
本文介绍了我无法在没有安装SqlServer Express的计算机上运行Sql Server localdb连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用Visual Studio 2012编写的C#控制台应用程序.在该应用程序中,我正在使用与数据库的Sql Server localdb连接来存储信息.在几台都安装了Visual Studio的计算机上,这可以正常工作.

I have a C# console application written using Visual Studio 2012. In the application I am using a Sql Server localdb connection to a database to store information. This is working fine on several computers, all of which have Visual Studio installed.

我想部署一个程序,仅安装Sql Server Express LocalDB,而不安装较大的Sql Server Express.但是,我的应用程序未在目标计算机上运行.我已经在目标计算机上安装了Sql Server Express LocalDB 2014.我可以使用命令行,使用sqllocaldb运行命令来验证它是否已安装并正在运行.

I would like to deploy a program that only has to install the Sql Server Express LocalDB, and not the larger Sql Server Express. However, my application is not running on the target computers. I have installed Sql Server Express LocalDB 2014 on a target computer. I can, using a command line, run commands using sqllocaldb to verify that it is installed and running.

C:\Users\someuser\Desktop\Debug>sqllocaldb v
Microsoft SQL Server 2014 (12.0.2000.8)`

但是,当我在同一台目标计算机上运行应用程序时,出现以下错误.

When I run my application on that same target computer, however, I get the following error.

C:\ Users \ someuser \ Desktop \ Debug> Testing_Console
11:21:07,912 [1]信息TestingConsole.Program-当前目录为C:\ Users \ someuser \ Desktop \ Debug
附加信息:(空)


未处理的异常:System.Data.SqlClient.SqlException:建立与SQL Server的连接时发生与网络相关或特定于实例的错误.服务器未找到或无法访问.验证实例名称正确,并且已将SQL Server配置为允许远程连接. (提供者:SQL网络接口,错误:50-发生本地数据库运行时错误.无法创建自动实例.有关错误详细信息,请参见Windows应用程序事件日志.

C:\Users\someuser\Desktop\Debug>Testing_Console
11:21:07,912 [1] INFO TestingConsole.Program - Current Directory is C:\Users\someuser\Desktop\Debug
Extra Info: (null)


Unhandled Exception: System.Data.SqlClient.SqlException: 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: 50 - Local Database Runtime error occurred. Cannot create an automatic instance. See the Windows Application event log for error details.

以下是我的app.config文件的开头,我在其中定义连接字符串.我尝试将直接文件路径放入LM文件,但这并不能解决问题.但是,这是可以预期的,因为该程序可以在安装了Visual Studio的计算机上的任何目录中运行.

The following is the beginning of my app.config file, where I am defining the connection string. I have tried putting in the direct file path to the LM file, but that didn't fix the issue. That was to be expected, however, as the program works from any directory on the computers with Visual Studio installed.

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
  </configSections>
  <connectionStrings>
    <add name="KomoLM_Console.Properties.Settings.LMConnectionString"
      providerName="System.Data.SqlClient"
      connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\LM.mdf;Integrated Security=True;MultipleActiveResultSets=True"
 />
  </connectionStrings>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
  </startup>

我不知道问题是否与仅安装SQL Server Express LocalDB 2014有关.谁能告诉我我的问题可能是什么?

I don't know if the issue is related to only have SQL Server Express LocalDB 2014 installed. Can anyone tell me what my problem might be?

推荐答案

问题与安装Sql Server Express LocalDB 2014而不是2012有关.该版本的MS更改了连接字符串要求.连接字符串是Data Source=(LocalDB)\MSSQLLocalDB,而不是Data Source=(LocalDB)\V11.0.更改我的连接字符串后,该程序将在仅安装了LocalDB 2014的计算机上正常运行.这是有关此文章的链接:

The problem was related to having Sql Server Express LocalDB 2014 installed instead of 2012. With that version MS has changed the connection string requirements. Instead of Data Source=(LocalDB)\V11.0, the connection string is Data Source=(LocalDB)\MSSQLLocalDB. After changing my connection string the program is running correctly on a computer that only has the LocalDB 2014 installed. Here is a link to an article about it: https://connect.microsoft.com/SQLServer/feedback/details/845278/sql-server-2014-express-localdb-does-not-create-automatic-instance-v12-0

http://msdn.microsoft.com/en-us/library/hh510202(v = sql.120).aspx

这篇关于我无法在没有安装SqlServer Express的计算机上运行Sql Server localdb连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆