首页 > 解决方案 > SQL 网络接口,错误:50 - 发生本地数据库运行时错误

问题描述

我有一项可以从(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服务器上的数据库。

我在SQLEXPRESS服务器上运行 SQL Server ( )。但它应该MSSQLLocalDB运行 SQL Server ( ) 吗?我没有看到那个。那是问题吗?或者是别的什么?

我的服务在服务器上运行,因为我可以从中提取不在数据库中的数据,它只是从数据库中提取不在服务器上工作的函数。

更新:

我安装了新版本的 SQL,但仍然出现同样的错误: 在此处输入图像描述

在此处输入图像描述 我尝试过:

 //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.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc) 的 System.ServiceModel.Channels.ServiceChannel.ThrowIfFaultUnderstood(Message reply, MessageFault fault, String action, MessageVersion version, FaultConverter faultConverter)。 ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout) 在 System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation) 在 System. ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage 消息)

在 [0] 处重新抛出异常:在 System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) 在 IService1.nextmatch(日期时间项)在 Service1Client.nextmatch(日期时间项)

我如何找到正确的实例>

标签: c#sql-server

解决方案


如果您使用的是 Amazon RDS Db,则需要先下载驱动程序,然后连接到您的数据库。也许这个链接可以帮助你连接你的数据库。


推荐阅读