When i click button an I always get an Error thatAn error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)

This is My connection string

string conn =@"Data Source = .;Initial Catalog= Product;Integrated Security = True"; DataTable objDT = new DataTable();
                SqlConnection objCon = new SqlConnection(conn);
                objCon.Open();SqlDataAdapter objDA = new SqlDataAdapter("Select* from product", objCon);
                objDA.Fill(objDT);
                objCon.Close();
                this.dataGridView1.DataSource = objDT;

            }
            catch (Exception ex)
            {
                MessageBox.Show("The Systems generated following error: " + ex.Message);
            }

Please Help me . I Have a Big Trouble

Follow these steps it may help you to fix error..

1-Go to All Programs >> Microsoft SQL Server 2008 >> Configuration Tools >> SQL Server Configuration Manager >> SQL Server Services, and check if SQL Server service status is “Running”.

In addition, ensure that your remote server is in the same network. Run “sqlcmd -L” in your command prompt to ascertain if your server is included in your network list.

2-Go to All Programs >> Microsoft SQL Server 2008 >> Configuration Tools >> SQL Server Configuration Manager >> Select TCP/IP.than Right Click on TCP/IP >> Click on Enable.You must restart SQL Server Services for all the changes to take effect. Right click and go to menu properties to select location where default port of SQL Server can be changed.

3-Go to Control Panel >> Windows Firewall >> Change Settings >> Exceptions >> Add Port.Make the following entries in popup “Add a Port” and click OK.
Name : SQL
Port Number: 1433
Protocol: Select TCP

4-Right click on the server node and select Properties. than Go to Left Tab of Connections and check “Allow remote connections to this server”

5-Go to All Programs >> Microsoft SQL Server 2008 >> Configuration Tools >> SQL Server Configuration Manager >> SQL Server Browser

6-Create exception of sqlbrowser.exe in Firewall
Search for sqlbrowser.exe on your local drive where SQL Server is installed. Copy the path of the sqlbrowser.exe like C:\Program Files\Microsoft SQL Server\90\Shared\sqlbrowser.exe and create the exception of the file in Firewall, as delineated in Step 3.

7-Go to All Programs >> Microsoft SQL Server 2008 >> Configuration Tools >> SQL Native Client 10.0 Configuration >> Aliases

Delete the alias that is giving problem and recreate it with identical parameters.


I have tried my best to include all the methods of fixing this error and if I have missed any, please leave a comment and I will be very glad to include them here.

Thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.