Microsoft Dot Net Master

Microsoft Dot Net Master
Microsoft Dot Net Master

Wednesday, March 28, 2012

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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)

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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)”. I didn’t get why this happened because previously it worked perfectly. To solve this problem I did some research and found solution at that time I decided to write post to help someone who is in need with this problem.  Check below methods to solve this problem.

First Method

Open SQL Server Management Studio now Connect window will open check whether you given proper Server Type and Server Name or not because if we give incorrect details then we have a chance to get this issue.


 
Second Method

1.      Go to Start >> Select All Programs >> Microsoft SQL Server 2008 R2 >> Configuration Tools >> SQL Server Configuration Manager

 

(Note: I installed SQL Server is 2008 R2 version in my laptop that’s why I selected Configuration Tools from Microsoft SQL Server 2008 R2 in case yours is Microsoft SQL Server 2008 then select Configuration Tools from that SQL Server version)

2.      After open SQL Server Configuration Manager >> Select SQL Server Services >> Select SQL Server (MSSQLSERVER) and check the status of SQL Server (MSSQLSERVER) whether is it running or not 



3.      If SQL Server (MSSQLSERVER) Status is in Running it’s ok otherwise right click on SQL Server (MSSQLSERVER) and click Start

4.      Now select SQL Server Network Configuration >> Select Protocols for MSSQLSERVER >> TCP/IP and check status of TCP/IP whether is it enabled or not if that TCP/IP state is in Disabled state right click on it and Enable that one.














Now restart your SQL Server Management Studio and check it I hope it will work for you.

A potentially dangerous Request.Form value was detected from the client in asp.net

"A potentially dangerous Request.Form value was detected from the client in ASP.NET WebForms"

Sample data I used to insert in database

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>

</div>
</form>
</body>
</html>
After enter the above formatted html data in Rich Textbox and I tried to insert data then I got error message like 
 


Server Error in ‘/RichTextboxSample’ Application.

A potentially dangerous Request.Form value was detected from the client (remarks =”<html></html>”)

Description: Request Validation has detected a potentially dangerous client input value, and processing of the request has been aborted. This value may indicate an attempt to compromise the security of your application, such as a cross-site scripting attack. You can disable request validation by setting validateRequest=false in the Page directive or in the configuration section. However, it is strongly recommended that your application explicitly check all inputs in this case.

Exception Details: System.Web.HttpRequestValidationException: A potentially dangerous Request.Form value was detected from the client (remarks="<html></html>5678,<c…").

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
This error occurs during insertion of html format data into database to eliminate this error we need to set ValidateRequest="false" in @Page line of web page or web.config file to solve security problems.

To solve this problem we need to add the ValidateRequest="false" in @Page line of web page like this

WebForms

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" ValidateRequest="false" %>
In this way we need to set ValidateRequest="false" in required pages otherwise we can set it globally to work for all the pages without having this error we need to add ValidateRequest="false" in web.config file under system.web section like this

Web.Config

<system.web>
………………………
<pages validateRequest="false">
</pages>
………………………
</system.web>
After set this property in webpage or web.config my problem has sovled and my code works perfectly. I hope it helps to solve your problem.
 

Windows Presentation Foundation (WPF)

The Windows Presentation Foundation is Microsoft’s next generation UI framework to create applications with a rich user experience. It is part of the .NET framework 3.0 and higher.
WPF combines application UIs, 2D graphics, 3D graphics, documents and multimedia into one single framework. Its vector based rendering engine uses hardware acceleration of modern graphic cards. This makes the UI faster, scalable and resolution independent.