userJJL
userJJL

Reputation: 55

Can't connect to Database on remote SQL server from Visual Studio 2013

I have created a program in Visual Studio 2010 with C# and XAML and a dataconnection to a SQL server where the data is stored. But then my company had to change to windows 7 – there was XP on my machine before – and I also had to change to Visual Studio 2013. My problem is I can’t connect to the database on SQL server in the new Visual Studio 2013 Professional. I can see and edit the tables from server explorer just fine. And I have also checked that the connectionstring is correct. I have also checked the TCP/IP settings, because it’s a remote network server and it seems enabled and just fine with port 1433. I have also tried to change the dataclasses but still no luck. When I connect to the server from SQL Server Management Studio it works just fine. But in Visual Studio 2013 I get the error on my observablecollection with the network related error 26: “SQL Network Interfaces, error: 26 – Error Locating Server/Instance Specified”. I don’t know how to solve the problem and any help is much appreciated.

     private T_Patient _T_Patient;
    public T_Patient T_Patient
    {
        get { return _T_Patient; }
        set { _T_Patient = value; }
    }

    private ObservableCollection<T_Patient> _observableCollection;
    private CollectionViewSource _collectionViewSource;
    /// <summary>
    /// Constructor for Patienter with observablecollection
    /// </summary>
    public Patienter()
    {

        InitializeComponent();

        using (var dc = new DataClasses2DataContext())
        {
            _observableCollection = new ObservableCollection<T_Patient>(dc.T_Patients);
        }

        _collectionViewSource = (CollectionViewSource)this.FindResource("_T_PatientViewSource") as CollectionViewSource;
        _collectionViewSource.Source = _observableCollection;

        _collectionViewSource.Filter += FilterName;
        _collectionViewSource.Filter += FilterID;

        this.T_Patient = new T_Patient();
        this.DataContext = T_Patient;
    }

By the way, I have tried to make a new datagrid to connect to the database in SQL server and It worked fine. So maybe there is an error in the mapping, which I don't know how to set.

Upvotes: 2

Views: 1941

Answers (2)

userJJL
userJJL

Reputation: 55

I found the solution, but it was very odd and had very little to do with the connection on the SQL server. I just had to move my project to the correct folder where Visual Studio saves the projects on local drive C. I had saved my project on the companys network folder.

I found the answer here, when I was trying to build the project again and I was also unable to drag controls from datasource.

https://social.msdn.microsoft.com/Forums/en-US/9fc4f835-d6c0-4d04-86c2-779c1f8e0791/unable-to-drag-data-source-to-control-to-bind

Upvotes: 1

Kumar C
Kumar C

Reputation: 132

This Blog Post from Microsoft Might Help.

An Excerpt from the Blog

Users often see this error message when connection to a SQL Server and don't know where to start to solve the problem. In most forums, people says this is because remote connection is not enabled on the server. This is not exactly correct. Actually, this error message give customers very specific information and the solution is quite simple.

First of all, you get this error message only if you are trying to connect to a SQL Server named instance. For default instance, you never see this. Why? Because even if we failed at this stage (i.e. error locating server/instance specified), we will continue to try connect using default values, e.g defaul TCP port 1433, default pipe name for Named Pipes. You may see other error message due to failure later, but not this error message.

Every time client makes a connection to SQL Server named instance, we will send a SSRP UDP packet to the server machine UDP port 1434. We need this step to know configuration information of the SQL instance, e.g., protocols enabled, TCP port, pipe name etc. Without these information, client does know how to connect the server and it fails with this specified error message.

In a word, the reason that we get this error message is the client stack could not receive SSRP response UDP packet from SQL Browser. It's easy to isolate the issue. Here are the steps: 1) Make sure your server name is correct, e.g., no typo on the name. 2) Make sure your instance name is correct and there is actually such an instance on your target machine. [Update: Some application converts \ to . If you are not sure about your application, please try both Server\Instance and Server\Instance in your connection string] 3) Make sure the server machine is reachable, e.g, DNS can be resolve correctly, you are able to ping the server (not always true). 4) Make sure SQL Browser service is running on the server. 5) If firewall is enabled on the server, you need to put sqlbrowser.exe and/or UDP port 1434 into exception.

Upvotes: 0

Related Questions