1
votes

I have a service that can pull data from a (LocalDB)\MSSQLLocalDB database. This works fine on my computer, but then I run the service on my AWS server, and try to pull data from the database I get this error:

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. The specified LocalDB instance does not exist.)

My connection code is this:

    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();
    }

My database is in the same location on both my computer and my server. I have Microsoft SQL Server Management Studio installed on my server and I can connect to and view the Wrestling.MDF database on that server.

I have SQL Server (SQLEXPRESS) running on the server. but should it be SQL Server (MSSQLLocalDB) running? I do not see that one. Is that the problem? Or is it something else?

My service is running on the server, because I can pull data from it that is not in the database it is only the function that pull from the database that is not working on the server.

Update:

I in stalled the new version of SQL but I am still getting this same error : enter image description here

enter image description here I have tried :

 //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";

but nothing is working... why?

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.)

Server stack trace: at System.ServiceModel.Channels.ServiceChannel.ThrowIfFaultUnderstood(Message reply, MessageFault fault, String action, MessageVersion version, FaultConverter faultConverter) at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc) at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout) at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation) at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]: at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) at IService1.nextmatch(DateTime item) at Service1Client.nextmatch(DateTime item)

how do I find the right instance>

2
sqlexpress is not localdb. Use the instance name you see in Management Studio.Crowcoder
Also, it really helps to READ the error message. Can not find server means no, you do not open an exception with "i have a problem in the server". Same way your car is not broken if it is stolen. And no, (LocalDB) is NOT local SQL Server express. connectionstrings.com has all connection string relevant info you ever need.TomTom
Crowcoder, what do you mean use the Use the instance name you see in Management Studio? use it where ?BBoone

2 Answers

0
votes

If you are using Amazon RDS Db need first to download the driver and then connect to your database. Maybe this link can help you to connect with your db.

-1
votes

Head over to https://www.connectionstrings.com/ and fix your connection information.(LocalDb) is not the same as a local SQL Server express. for which https://www.connectionstrings.com/sql-server/ gives.... ".\SqlExpress" as server. Which, btw., needs to have AttachDbFileName (does that still work? Not used Express for like 10 years) because it does NOT automatically attach an MDF file.