Webparts do not work

Trying to use my first webpart I got this unfriendly error message from the run-time:
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)
I was a bit shocked as I did not do anything to break it Smile. It took me some time to figure out that the .NET 2.0 configuration expects you to have SQL Express installed, which I did not have and did not want to. To get profiles and webparts working with my SQL 2000 Server the following steps were required to change the machine settings:
  1. Create the aspnetdb database on SQL server.
  2. Add a connection string for the aspnetdb to machine.config.
  3. Change the connectionStringName attributes for the relevant providers in machine.config and web.config (that’s where the webpart provider is).
Alternatively you can remove and add the keys in web.config of you web application if you do not want to or cannot change the machine configuration.

1. Create aspnetdb

Start a visual studio command prompt and type the following command to generate the create script for the database: aspnet_regsql.exe -A all -sqlexportonly C:\createaspnetdb.sql. Than run that script on your database using query analyzer. Verify that the database called ‘aspnetdb’ was created.


2. Add connection string

Locate your machine config which is typically at c:\windows\microsoft.net\framwork\<version>\CONFIG\machine.config. Add to configuration\connectionString something like that:

<add name="aspnetdb" providerName="System.Data.SqlClient" connectionString="Data Source=localhost;Initial Catalog=aspnetdb;Integrated Security=True" />


3. Change connectionStringName attribute

Find the AspNetSqlMembershipProvider, AspNetSqlProfileProvider, AspNetSqlRoleProvider in machine.config and the AspNetSqlPersonalizationProvider in web.config in the CONFIG folder and change the connectionStringName attribute from ‘LocalSqlServer’ to ‘aspnetdb’ .

That should be it.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.