Friday, February 15, 2008

Web Parts common Error when getting started

A common error many ASP.NET 2.0 beginner developers make is that when they decide to get into WebParts they drag a WebPartManager on the screen and a WebPartZone and then bung in a control. To their dismay, when they press F5 to run the program they get a nasty error like this:

Error:Server Error in '/WebSite1' Application.--------------------------------------------------------------------------------
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: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified) 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. SQLExpress database file auto-creation error:

Now this error may appear completely unrelated and confusing but it makes sense when you know why ASP is complaining. Basically the WebPartManager is trying to contact the profile store to save your persoanlisation settings, which happen to default to SQLServer by default. Now your app is clean and you have not specified anywhere that you wanted to SQL as your profile storeor perhaps you don't have SQL even installed. So to get around this just switch off the webpartmanager personalisation by setting its personalisation attribute to false:

<asp:webpartmanager id="webpartManagerSampleSite" runat="server" enabled="false"></asp:webpartmanager>

No comments: