search

Google
 

Thursday, December 20, 2007

SqlClient.SqlException - An error has occurred while establishing a connection to the server


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


Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.


Exception Details: System.Data.SqlClient.SqlException: An 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)


If you are new to .net you will surely face the following error.

Solution for the error as follows

Follow the path

Start -> All Programs
-> Microsoft SQL server 2005
-> Configuration Tools
->SQL Server Surface Area Configuration







Now you will be land to SQL Server 2005 Surface Area Configuration window.

Now Click
Surface Area Configuration for Services and Conditions(2nd bottom).











Soon you will land to SQL Server 2005 Surface Area Configuration window

Goto
DataBase Engine -> Remote Connections

By Default Local Connections only will be selected.








Change it by selecting Local and remote connection.
Options under Local and remote connection will be by default Using TCP/IP only.


Select the last option
Using both TCP/IP and named pipes.

click apply and then ok.



Dont Forget to Restart SQL Server.

Page Navaigation In .Net 2.0

WebPage Navigation
You may be wondering how we do perform page navigations especially in the code behind I mean without html controls or asp.net controls. We have few Commands that need to be remembered and should be used depending upon our requirement.


Server.Transfer is similar to Response.Redirect in sense that it sends the user to another page with a statement such as Server.Transfer("WebForm2.aspx"). However, the statement has a number of distinct advantages and disadvantages.


Firstly, transferring to another page using Server.Transfer conserves server resources. Instead of telling the browser to redirect, it simply changes the "focus" on the Web server and transfers the request. This means you don't get quite as many HTTP requests coming through, which therefore eases the pressure on your Web server and makes your applications run faster.


"transfer" process can work on only those sites running on the server, you can't use Server.Transfer to send the user to an external site. Only Response.Redirect can do that.


Secondly, Server.Transfer maintains the original URL in the browser. This can really help streamline data entry techniques, although it may make for confusion when debugging.
The Server.Transfer method also has a second parameter—"preserveForm". If you set this to True, using a statement such as Server.Transfer("WebForm2.aspx", True), the existing query string and any form variables will still be available to the page you are transferring to.


For example, if your WebForm1.aspx has a TextBox control called TextBox1 and you transferred to WebForm2.aspx with the preserveForm parameter set to True, you'd be able to retrieve the value of the original page TextBox control by referencing
Request.Form("TextBox1").


In brief Response.Redirect simply tells the browser to visit another page. Server.Transfer helps reduce server requests, keeps the URL the same and, with a little bug-bashing, allows you to transfer the query string and form variables.