Saturday, January 7, 2012

Common errors and solutions of ASP.net

1.When you debug an ASP.NET application in Visual Studio .NET, you may receive the following error message:

Error while trying to run project: Unable to start debugging on the web server. The project is not configured to be debugged.
Possible Solution: To do this goto IIS management console and then go to your virtual directory in IIS.Right click and go to properties of virtual directory/website. Then goto Directory Security tab and then click Edit button under anonymous control and authentication control and then make sure to check the last checkbox which states Integrated windows security.

2.Object reference not set to an instance of an object
Possible solution
This is basically a runtime eror and is caused by your code trying to reference an object that is not available, or set to null.Foreg: Connectionobject you have opened and sed and later on you closed it and set it to null and in the later part of code you try to use the connection again.Then you will encounter this error message.
This error may also occur when improperly call an object without the "new" keyword.

3. Cannot implicitly convert type 'object' to 'string'
Possible solution
The solution here is to append ".ToString() which will represents the object as a string.

4.'name' is a type and cannot be used as an expression
Possible solution
This can happen usually when you forget to use the new keyword when instantiating an object or invoking a constructor.

5. Only assignment, call, increment, decrement, and new object expressions can be used as a statement
Possible solution
a.If you call an object that requires parentheses() after the command, you will get this error. Ex. Conn.Open() not Conn.Open
b.Using an assignment operator as opposes to an equality operator

6. The name 'whatever' does not exist in the class or namespace / The type or namespace name 'whatever' could not be found (are you missing a using directive or an assembly reference?)
Possible solution
This occur when you have not declared a variable globally and or it is missing altogether or is improperly declared.

7. 'method name': not all code paths return a value
Possible solution
This will happen when you are trying to make a function method behave like a subroutine or vice-versa.Use the proper method keyword to remedy this. Void is for methods that do not return a value, although you could response write the output. Whereas, applying a keyword value like string, int, works alongside a return value at the end of the method.

8. 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)
at System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject)
at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)
at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
at System.Data.SqlClient.SqlConnection.Open()
The three most common problems are:
1. Sql Server not configured for remote connections.
2. Firewall blocking sql server connections.
3. Wrong data source in connection string.

No comments: