【发布时间】:2018-10-27 16:10:51
【问题描述】:
我有一项服务可以从(LocalDB)\MSSQLLocalDB 数据库中提取数据。这在我的计算机上运行良好,但随后我在我的 AWS 服务器上运行该服务,并尝试从数据库中提取数据,但出现此错误:
与 SQL Server 建立连接时出现与网络相关或特定于实例的错误。服务器未找到或无法访问。验证实例名称是否正确以及 SQL Server 是否配置为允许远程连接。 (提供者:SQL 网络接口,错误:50 - 发生本地数据库运行时错误。指定的 LocalDB 实例不存在。)
我的连接代码是这样的:
SqlConnection conn;
SqlCommand comm;
SqlConnectionStringBuilder connStringBuilder;
void ConnectToDb()
{
connStringBuilder = new SqlConnectionStringBuilder();
connStringBuilder.DataSource = @"(LocalDB)\MSSQLLocalDB";//"(LocalDB)\v11.0";
connStringBuilder.InitialCatalog = "WRESTLING.MDF";
connStringBuilder.Encrypt = true;
connStringBuilder.ConnectTimeout = 30;
connStringBuilder.AsynchronousProcessing = true;
connStringBuilder.MultipleActiveResultSets = true;
connStringBuilder.IntegratedSecurity = true;
string location = Directory.GetCurrentDirectory();
//Server=myServerAddress;Database=myDataBase;Trusted_Connection=True;
string temp = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename='C:\App_Data\Wrestling.mdf';Integrated Security=True";
// string temp = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename='F:\Projects\Bailey Service\Bailey Service\App_Data\Wrestling.mdf';Integrated Security=True";
conn = new SqlConnection(temp);
comm = conn.CreateCommand();
}
我的数据库在我的计算机和服务器上的相同位置。我的服务器上安装了 Microsoft SQL Server Management Studio,我可以连接并查看该服务器上的 Wrestling.MDF 数据库。
我在服务器上运行 SQL Server (SQLEXPRESS)。但它应该运行 SQL Server (MSSQLLocalDB) 吗?我没有看到那个。那是问题吗?还是别的什么?
我的服务正在服务器上运行,因为我可以从中提取不在数据库中的数据,它只是从数据库中提取不在服务器上的函数。
更新:
我安装了新版本的 SQL,但仍然出现同样的错误: enter image description here
enter image description here 我试过了:
//Server=myServerAddress;Database=myDataBase;Trusted_Connection=True;
// string temp = @"Data Source=MOXL0063\TEW_SQLEXPRESS; Integrated Security = True";
string temp = @"Data Source=(LocalDB)\v11.0;AttachDbFilename='C:\App_Data\Wrestling.mdf';Integrated Security=True";
// string temp = @"Data Source=(LocalDB)\MSSQLSERVER;AttachDbFilename='C:\App_Data\Wrestling.mdf';Integrated Security=True";
但没有任何工作... 为什么?
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.ServiceModel.Channels.ServiceChannel.ThrowIfFaultUnderstood(消息回复、MessageFault 故障、字符串操作、MessageVersion 版本、FaultConverter faultConverter) 在 System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime 操作,ProxyRpc& rpc) 在 System.ServiceModel.Channels.ServiceChannel.Call(字符串操作,布尔单向,ProxyOperationRuntime 操作,Object[] 输入,Object[] 输出,TimeSpan 超时) 在 System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime 操作) 在 System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage 消息)
在 [0] 处重新抛出异常: 在 System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg,IMessage retMsg) 在 System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData,Int32 类型) 在 IService1.nextmatch(日期时间项) 在 Service1Client.nextmatch(DateTime 项)
如何找到合适的实例>
【问题讨论】:
-
sqlexpress 不是本地数据库。使用您在 Management Studio 中看到的实例名称。
-
另外,阅读错误信息确实很有帮助。找不到服务器意味着不,您没有打开“我的服务器有问题”的异常。同样,如果您的汽车被盗,您的汽车也不会损坏。不,(LocalDB)不是本地 SQL Server 快递。 connectionstrings.com 拥有您需要的所有连接字符串相关信息。
-
Crowcoder,你是什么意思使用你在 Management Studio 中看到的实例名称?用在哪里?
标签: c# sql-server