SQL网络接口,错误:50-发生本地数据库运行时错误

时间:2018-10-27 16:10:52

标签: c# sql-server

我有一个可以从(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 [] ins,Object [] outs,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(DateTime项目)    在Service1Client.nextmatch(DateTime项目)上

如何找到合适的实例>

2 个答案:

答案 0 :(得分:0)

如果您正在使用Amazon RDS Db,则需要先下载驱动程序,然后再连接到数据库。也许link可以帮助您连接数据库。

答案 1 :(得分:-1)

转到https://www.connectionstrings.com/并修复您的连接信息。(LocalDb)与本地SQL Server Express不同。 https://www.connectionstrings.com/sql-server/为其提供....“。\ SqlExpress”作为服务器。顺便说一句,因为它不会自动附加MDF文件,所以它需要具有AttachDbFileName(它仍然可以工作吗?大约十年没有使用Express了。)。