SQL Server error when trying to connect

Alan Spurlock

So I am having a problem connecting to my sql server.

I know 100% its working and accepting connections, but for some reason I keep getting an error.

I can browse the server just fine in Server Browser, and If I bind the datasource to a datagrid, I can preview the table as well. So I know it's working fine inside VS, but not runtime.

From my knowledge and experience, if VS can connect to the server and display all the good stuff, then it should be able to do it during runtime??

Any help and advice is much appreciated.

Non Duplicate Reason The reason I believe my question is not a duplicate, is because my application is not a ASP or an MVC app. It's a winforms application. So many of the suggestions do not work for me. I have written 2 c# programs now (one wpf and one winform) to access our SAP database and they work just fine. The SAP database is located on the same server as the one I am trying to connect to. I can browse the server perfectly fine in SQL-Server Management Studio on my machine. I can also browse the server perfectly fine in Visual Studios server browser. But When I debug the program, it halts with this error.

My Connection code

public string connectionString = @"Data Source=ENGSRV\SIGMANEST;Initial Catalog=SNDBase10;Persist Security Info=True;User ID=XXXXX;Password=XXXXX";
private void btnSearch_Click(object sender, EventArgs e)
{
    SqlConnection connection = new SqlConnection(connectionString);
    SqlCommand cmd = new SqlCommand();

    try
    {
        try
        {
              connection.Open();
              MessageBox.Show("Connected");
        }
        catch (Exception ex)
        {
                    throw;
                    //MessageBox.Show(ex.Message, "Database Error!");
        }
   }
   catch (Exception ex)
   {
         throw;
         //MessageBox.Show(ex.Message, "Connection Error!");
    }
}

Error Code

An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in ProductionOrderQuery.exe

Additional information: 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: 26 - Error Locating Server/Instance Specified)

Server Explorer Screen Shot

Table Data Rows Screen Shot

Update: So after thinking about it tonight, I believe it has to do with my firewall and nothing to do with the sql server or the firewall on the server. Here's why, My VB.Net application that can successfully connect to the sql server is not a standalone application. It's a plugin for a CAD software called Rhinocreos 5. All our CAD Designers have 0 problems pulling data from the sql server from within Rhino... Visual Studio can connect with 0 problems in the Server Explorer... Which now leaves me to believe that the application(plugin), is piggy-backing of a firewall rule Rhinocreos 5 made during its installation. If I change the connection string to the one I posted here, it connects perfectly. But it will not find the sql server instance in my standalone application.

That being said, I guess I need to research on how to promaticaly add my program to the clients firewall rules to access the network.

Thanks to everyone that has helped my solve this. If anyone has any tips or pointers to allowing my program through firewalls on any client it's installed on, let me know.

Alan Spurlock

Problem was within our network.

Our IT guy decided to have all our computers "My Documents" on a separate server and NOT on our own machines.

So Visual Studio by default saved my project to this server and not to my own computer. This was causing the block to the SQL Server.

I solved this by simply moving my project to my actual documents folder on my computer.

Thanks everyone for the help and pointers!

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Android app error when trying to connect to SQL Server 2005

From Dev

'SqlException was unhandled' error when trying to connect to SQL Server database

From Dev

Error when trying to connect to Team Foundation Server

From Dev

Error trying to connect to SQL Server database

From Dev

Error when trying to open() sql server

From Dev

mongodb server error when trying to connect with angularJS $http

From Dev

401 error using Alamofire and swift when trying to connect to my server

From Dev

Getting a 404 error when trying to connect to socket io/express server

From Dev

Error 500 when trying to connect to Team Foundation Server

From Dev

ClassNotFoundException when trying to connect to SQL server 2005 with Java

From Dev

ClassNotFoundException when trying to connect to SQL server 2005 with Java

From Dev

SQL syntax error when trying to connect Play application to mysql database

From Dev

SQL Server: getting error 26 when connect to server

From Dev

Error 21 when trying to delete a SQL Server DB

From Dev

Why the SQL Server error when many clients are trying to write to a table?

From Dev

Error 21 when trying to delete a SQL Server DB

From Dev

Error when trying to backup data from SQL Server

From Dev

SIGBART error trying to connect to a TCP server on iOS

From Dev

Error trying to connect the FCM CCS server with sleekxmpp

From Dev

Trying to connect XMPP server by Smack and getting error

From Dev

Algorithm Negotiation failed when trying to connect to server

From Dev

Connection refused when trying to connect to bluetooth server

From Dev

Getting unauthorized when trying to connect to server side

From Dev

Keep getting No X509TrustManager implementation available error when trying to connect to web socket server

From Dev

Keep getting No X509TrustManager implementation available error when trying to connect to web socket server

From Dev

Why SMTP ERROR: Failed to connect to server: No route to host (65) when trying to send email with PhpMailer?

From Dev

Bizarre error when trying to connect to database

From Dev

Error "no such table CUSTOMERS" when trying to connect to Windows Azure SQL database with Delphi FireDac

From Dev

Oracle Express: Getting ORA-12154 error when trying to connect using SQL Plus

Related Related

  1. 1

    Android app error when trying to connect to SQL Server 2005

  2. 2

    'SqlException was unhandled' error when trying to connect to SQL Server database

  3. 3

    Error when trying to connect to Team Foundation Server

  4. 4

    Error trying to connect to SQL Server database

  5. 5

    Error when trying to open() sql server

  6. 6

    mongodb server error when trying to connect with angularJS $http

  7. 7

    401 error using Alamofire and swift when trying to connect to my server

  8. 8

    Getting a 404 error when trying to connect to socket io/express server

  9. 9

    Error 500 when trying to connect to Team Foundation Server

  10. 10

    ClassNotFoundException when trying to connect to SQL server 2005 with Java

  11. 11

    ClassNotFoundException when trying to connect to SQL server 2005 with Java

  12. 12

    SQL syntax error when trying to connect Play application to mysql database

  13. 13

    SQL Server: getting error 26 when connect to server

  14. 14

    Error 21 when trying to delete a SQL Server DB

  15. 15

    Why the SQL Server error when many clients are trying to write to a table?

  16. 16

    Error 21 when trying to delete a SQL Server DB

  17. 17

    Error when trying to backup data from SQL Server

  18. 18

    SIGBART error trying to connect to a TCP server on iOS

  19. 19

    Error trying to connect the FCM CCS server with sleekxmpp

  20. 20

    Trying to connect XMPP server by Smack and getting error

  21. 21

    Algorithm Negotiation failed when trying to connect to server

  22. 22

    Connection refused when trying to connect to bluetooth server

  23. 23

    Getting unauthorized when trying to connect to server side

  24. 24

    Keep getting No X509TrustManager implementation available error when trying to connect to web socket server

  25. 25

    Keep getting No X509TrustManager implementation available error when trying to connect to web socket server

  26. 26

    Why SMTP ERROR: Failed to connect to server: No route to host (65) when trying to send email with PhpMailer?

  27. 27

    Bizarre error when trying to connect to database

  28. 28

    Error "no such table CUSTOMERS" when trying to connect to Windows Azure SQL database with Delphi FireDac

  29. 29

    Oracle Express: Getting ORA-12154 error when trying to connect using SQL Plus

HotTag

Archive