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.

Wednesday, November 28, 2007

Creating 3-Tier Architecture in .NET


Today I would like to write about how to create Three-Tier architecture
Guys who have just started working on .net may have questions in their minds
What is this ‘three tier architecture?, Why three tier architecture? Why to follow it.? and so on……………….



I was in the same illusion when I have started working on .net and told to follow it.

There are many reasons to tell why we need an architecture .I want to tell you few of that I know:-
1) To make our code more modular.

2) Readability increases.

3) Fixing bugs is easier.

4) To follow certain standard’s.


I would like to illustrate how to and what is the need to follow.
Architecture may not be of three tiers always .It has been chosen to follow because it may be a clients request or company standards. But it is always better to have an architecture for your project and to follow specific standards through out the project.




Three tier architecture looks like.






1) UIL(User Interface Layer)

2) BLL(Business Logic Layer)

3) DAL(Data Access Layer)

Now we shall start building the specified architecture. Firstly choose the location where you want your project to be placed, location can be in any partition of your memory (like C drive or D drive ………). Create a folder in that specific drive and name the folder that you have chosen for your project.


NOTE: Remember always choose project name that best describes your project and it must be appropriate.


Create two subfolders Named CompleteBuild(optional name) and Database.
Place all procedure in the database folder and create a folder called UIL in the CompleteBuild.



Creating Virtual Directory

Now go to run (windows key + r), type inetmgr then press enter.You will be able to view the IIS window as below.




On the left side of the window you can view local computer, expand it you will observe Web Sites and then choose Default Web Sites to expand .Move the mouse over Default Web Site link right click then select New option from that select and Click Virtual Directory.......

local computer -> Web Sites -> Default Web Site -> (right click and choose) New -> Virtual Directory






Now you will observe another window which will be similar to this image.


Click on next.













Now it will ask you to give alias name .Choose an appropraite name to fill the text box.
After filling text box click on next .






Now you need to enter physical path of your project where it is located.
like C:\OurSpace\Complete Build\UIL
After done, click on next.







Just check Browse option in the access permissions window and dont do any thing else.
Done with it, then click on next.




Virtual directory has been created successfully if you get this window.
Click on finish .




You can now see the virtual directory with the alias name you have given has been created in ths Defaut web sites (left side) and in the content side you will have no content but, if you are placing any files in UIL you can very well view them and browse depending upon the the permissions you have given in Access Permission Window.




Now, go to visual studio IDE choose New ->Web Site






you will be landing into this window choose ASP.NET Web Site or AJAX Enabled Web Site depending on your requirement.


Now look at the left-bottom of the window you will find location dropdown, select http then click on browse






you will find this window choose the physical directory you have just created.


Note:- you can only find virtual directory when you select IIS tab, which is located at the left side is selected.





Now we have to create two more layers BLL and DAL.These BLL and DAL are nothing but Class Library.Go to the solution explorer window, move your mouse on the Solution File then right click select Add -> Add New Project option you will find the window as shown .Choose

the location C:\OurSpace\CompleteBuildand name it as BLL.



Repeat the same for DAL layer.





We have created the three layers , now we need to set properties and relation among them.



Now go to the UIL right click to choose properties.

Choose Reference located at the left side.
when the window pops up click on Add Reference button.











Choose the projects tab, select BLL and

DAL(i have used EnterPrise Library instead of DAL)then click on ok.











Choose MS Build option from the left side and update Output Folders as C:\OurSpace\CompleteBuild\SolutionFiles\PrecompiledWeb\UIL and relate correspondingly yours donot exactly cut copy paste.



Go to solution file right click and choose properties select Project Dependencies tab located left side of the window.

select project

UIL

Check Depends On BLL

similarly select project BLL and check Depends On DAL and there is no need for DAL to set any property as it does not depend on any project, neither UIL nor BLL.

Now we have successfully created the specified architecture. If you haven't try, just try it you will surely make sense.


Tuesday, November 27, 2007

Why .NET

Hi Friends ,
Let me tell you why i have chosen .net as platform .

WHY .NET



.NET is the future of development not only for the Windows platform, but other operating systems as well. If you are not moving to .NET now, you should at least be keeping up to date with it and reevaluating it at regular intervals to determine when you will begin moving to it.

Some advantages that .net has over Java are:
  • Java is not just a platform, but a language। .NET is language independent.

  • Adopting .NET does not force you to adopt a single, or even specific .we can even support the Java language, and J# is very close to Java.
    Language interoperability.

  • .NET can coexist with and even integrate with existing Win32 code.
    Moving to Java from Win32 is a complete paradigm shift.

  • Moving to .NET is a more natural path for Win32 developers.


Technical Components Making Up The .NET Platform:
  • C#, a "new" language for writing classes and components, that integrates elements of C, C++, and Java, and adds additional features, like metadata tags, related to component development.


  • A "common language runtime", which runs bytecodes in an Internal Language (IL) format. Code and objects written in one language can, ostensibly, be compiled into the IL runtime, once an IL compiler is developed for the language.



  • A set of base components, accessible from the common language runtime, that provide various functions (networking, containers, etc.).


  • ADO+, a new generation of ADO data access components that use XML and SOAP for data interchange.

  • Win Forms and Web Forms, new UI component frameworks accessible from Visual Studio


  • ASP+, a new version of ASP that supports compilation of ASPs into the common language runtime (and therefore writing ASP scripts using any language with an IL binding).