views:

607

answers:

2

Is there anyway to change the ASPNETDB and also using SQLExpress (2005) user instance ?

I have changed my web.config's connectin string to

<remove name="LocalSqlServer"/>
<add name="LocalSqlServer"
     connectionString="Data Source=.\SQLEXPRESS;
     AttachDbFilename=|DataDirectory|\Kooft.mdf;
     User Instance=true;
     Integrated Security=True;
     Initial Catalog=Kooft;"
  providerName="System.Data.SqlClient" />

but every time I using ASP.Net Configuration Tool, it will create another ASPNETDB.mdf file in my App_Data folder.

+3  A: 
  1. Run aspnet_regsql.exe from your Framework 2.0 folder, mine is:

    C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727

  2. Go through the wizard and choose the database that you wish to add the AspNetDB tables too.

  3. Set the connectionstring to connect to your database e.g. (Anything in square brackets may possibly need changing and the brackets removed.

  4. Update your membership provider section of the web.config and set the following setting to be the connectionstringname from above:

    connectionStringName="INSERTCONNNSTRINGNAME"

Then you should be ready to roll. Remember to change the same setting on any role or personalization providers you may have already in the web.config.

John_
+2  A: 

First, create a new, empty database in your SQL Express instance.

Then run the aspnet_regsql.exe tool that can be found here:

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_regsql.exe

This will open a GUI wizard allowing you to select a database server and database to be set up with the default schema for the aspnet providers (membership, profile, roles).

Configure the security on the database appropriately - for best results, you probably want to enable Integrated Security, so ensure that the account the web site is runing under has access to the database, there are a number of Database Roles that are created for you - add your account to the appropriate ones.

Then, in your webconfig, you'd have something like:

    <connectionStrings>
 <remove name="LocalSqlServer"/>
 <add name="LocalSqlServer" 
  connectionString="Data Source=[ComputerName]\SQLEXPRESS;Initial Catalog=[DatabaseName];Integrated Security=True" 
  providerName="System.Data.SqlClient"/>
    </connectionStrings>

The key parts to update there are:

  • [ComputerName] - this should be the instance name of your SQL Express installation.
  • [DatabaseName] - this should be the name of the database you used in the first two steps.

That's certainly how I got mine up and running.

Zhaph - Ben Duguid
Thanks this certainly help me.
Kb