Visual C# Developer Center > Visual C# Forums > Visual C# General > Exception when filling table adapter
Ask a questionAsk a question
 

AnswerException when filling table adapter

  • Friday, November 06, 2009 5:54 PMEoinF Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Has Code
    i keep getting an exception the first time i run my program(it works when i click "retry")
    and then it doesnt cause an exception until the computer is restarted.
    Today i was clicking retry and it just kept on returning the exception.
    Is there a better way to do this, because this doesnt fix the problem:

    private void MainForm_Load(object sender, EventArgs e)
            {
    c:            try { this.listTableAdapter.Fill(this.cRevDatabaseDataSet.List); }
                catch (System.Data.SqlClient.SqlException)
                {
                    DialogResult result = MessageBox.Show("Failed to load database", "Error", MessageBoxButtons.RetryCancel);
                    if (result == DialogResult.Retry)
                        goto c;
                    else
                    {
                        Application.Exit();
                        return;
                    }
                }
    

    SqlException:
    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)

    any help on this would be greatly appreciated, thanks.

Answers

All Replies

  • Friday, November 06, 2009 8:40 PMTergiver Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    The problem is that SQL Server is unavailable when that exception occurs.

    Is SQL Server service running on that machine? Is the service set to startup automatic?

    Is SQL Server running on a network machine? It may be that your computer isn't connecting to the network prior to the first time your program is running.

    Most likely, the problem is not with your code, but is an outside issue.

  • Friday, November 06, 2009 8:58 PMChris Fo Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    You might also want to remove the GOTO C and rethink that method.

    This SQL Error can be caused by a few things, but we can't see how you're attempting to connect, and we also can't see your network topology.  What address is SQL listening on?  What protocols do you have set up for SQL on your client?  I would disable Shared Memory, Named Pipes and VIA.  Also make sure that the server has TCP/IP as the primary protocol.  If the other protocols are enabled on your client, modify the order so that TCP/IP is #1 and Named Pipes is #2.  You might also want to add an alias pointing to the TCP/IP address of your SQL Server.  Try pinging the server, is that successful?
  • Friday, November 06, 2009 9:31 PMTergiver Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    There's nothing wrong with your GOTO. You can safely ignore the anti-GOTO sentiment.
  • Friday, November 06, 2009 11:06 PMEoinF Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    well all ive done is create the database, cRevDatabase.mdf and set data bindings to a textbox, no use of network connections(the table adapter was created by c#, automaticaly when i set the text property of the textbox)
    thats all ive really done to acheive this section of code

    i only see that sqlwriter.exe is running and it shouldnt be cos im not running c# atm, so theres no need for it.
    i ended that process but it had no effect on my program
  • Tuesday, November 10, 2009 11:14 AMRoahn LuoMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Hello,

    Thanks for your post. It seems that it is a SQL Protocal issue here. The error happens because the the Client could not receive the response from SQL Browser. Is there any firewall on our machine? I suggest you put port 1434 in the exception since our packets are sent to the Server through it.

    There are several ways to isolate the issue, please refer to the blog below for more information:
    http://blogs.msdn.com/sql_protocols/archive/2007/05/13/sql-network-interfaces-error-26-error-locating-server-instance-specified.aspx

    Best regards,
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    If you have any feedback, please tell us.
    Welcome to the All-In-One Code Framework!
    • Marked As Answer byRoahn LuoMSFT, ModeratorFriday, November 13, 2009 5:24 AM
    • Unmarked As Answer byEoinF Tuesday, November 17, 2009 8:15 PM
    • Marked As Answer byEoinF Saturday, November 21, 2009 2:43 PM
    •  
  • Sunday, November 15, 2009 1:18 PMEoinF Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    I entered port 1434 as an exception into my routers configuration but i couldnt see where its done with my firewall so i just temporarily disabled it. That didnt work either

    the number 3 option, im not familiar with. how would i go about doing that?
  • Thursday, November 19, 2009 6:40 PMEoinF Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    bump