Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 4.0 aka C# 2010 > BOOK: Beginning Visual C# 2010
|
BOOK: Beginning Visual C# 2010
This is the forum to discuss the Wrox book Beginning Visual C# 2010 by Karli Watson, Christian Nagel, Jacob Hammer Pedersen, Jon D. Reid, Morgan Skinner, ; ISBN: 9780470502266
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning Visual C# 2010 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 13th, 2012, 05:23 AM
Registered User
 
Join Date: Apr 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to Overwrite ASPNETDB.MDF... HELP!

Hi, I'm using the MS Visual Web Developer 2010, the start-up website layout template they offer. I used the defualt login and register page as my way to create login pages. I also enabled roles and created admin and customer accounts in the ASP.NET Configaration.

Then I realised I have 2 databases in my app-data folder. One is my personal database with Users and all the details and this ASPNETDB.MDF database which seem to be saving up all the new users i register using the system. I can't seem to get my user details in my own database to link to the website instead of this default one. All my table names are as same as the ASPNETDB.MDF default database. Is there a way to do this? please help me out as I'm quite new to programming. Also this is being programed in C#Thank you.

Kind Regards

K
 
Old June 26th, 2012, 10:13 PM
Authorized User
 
Join Date: Jan 2011
Posts: 41
Thanks: 0
Thanked 1 Time in 1 Post
Default

My approach to this is deleting the aspnetDB database completely and then adding the tables in the aspnetDB to my database. When you do this though, you will need to do some changes in the web.config file to reflect your database as the database to use for membership. Follow the following steps.

1. Backup your project (in case this doesn't go as planned, hahaha!)
2. Delete the aspnetDb database.
3. In this step, you are going to configure your custom database to store information for ASP.Net applications services. So go to Drive C: > Windows > Microsoft.Net > Framework (or Framework64 if on a 64 bit PC like me) > v4.0.xxx (where xxx is th revision number of the version of .Net Framework you have, eg v4.0.30319) > Locate the aspnet_regsql.exe app. > double click
  • 3a. In the dialog that opens, read the screen and then click Next
  • 3b. On this screen there are two radio buttons. Because you already have a database, choose the first one. Click Next
  • 3c. Enter your Server Name ( use '.', dot for local machine), select the credentials for your database server.
  • 3d. From the Databases dropdown, select your database. Click Next.
  • Read the screen and then click Next

If all goes well, you should see a screen that lets you know. Click Finish.

Now you have completed the first part. The second part is to let asp.net know that you want it to use your database for membership services. To do this, go to web.config. Locate the connectionString for your database. Name the connection string appropriately.

Eg. Change the connectionString below to your liking.
Instead of this,
HTML Code:
<connectionStrings>
		<add name="LocalSqlServer" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient"/>
	</connectionStrings>
use

HTML Code:
<connectionStrings>
		<add name="MyDbConnectionString" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|MyCustomDB.mdf;User Instance=true" providerName="System.Data.SqlClient"/>
	</connectionStrings>
Now go and locate the machine.config file (usually at C:\Windows\Microsoft.NET\Framework64\v4.0.xxxx\Con fig)

Open the machine.config file VS and locate the following elements under <system.web>:

HTML Code:
<membership>
			<providers>
				<add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="LocalSqlServer" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="true" applicationName="/" requiresUniqueEmail="false" passwordFormat="Hashed" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="7" minRequiredNonalphanumericCharacters="1" passwordAttemptWindow="10" passwordStrengthRegularExpression=""/>
			</providers>
		</membership>
		<profile>
			<providers>
				<add name="AspNetSqlProfileProvider" connectionStringName="LocalSqlServer" applicationName="/" type="System.Web.Profile.SqlProfileProvider, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
			</providers>
		</profile>
		<roleManager>
			<providers>
				<add name="AspNetSqlRoleProvider" connectionStringName="LocalSqlServer" applicationName="/" type="System.Web.Security.SqlRoleProvider, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
				<add name="AspNetWindowsTokenRoleProvider" applicationName="/" type="System.Web.Security.WindowsTokenRoleProvider, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
			</providers>
		</roleManager>
Note that the connectionStringName attribute is all set to LocalSqlServer. That is a reference to the aspnetDB database you deleted. Now copy these elements from the machine.config file to your web.config file and replace the value for this attribute to the name you gave the connectionString for your custom database you just modified. You must not make changes to machine.config file. As the name depicts, settings in this file applies to all .net applications you build on this machine. So, make sure to only copy the elements listed above to your application's web.config file before making the changes.

You are all done.

NOTE: If you expand your custom db after running the aspnet_regsql program, you will notice all the necessary tables for keeping records are added.

Last edited by malie22001; June 26th, 2012 at 10:18 PM..





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to Overwrite ASPNETDB.MDF... HELP! freezer22 C# 4.0 aka C# 2010 General Discussion 0 April 13th, 2012 05:14 AM
ASPNETDB.mdf zdb5000 BOOK: Professional ASP.NET 4 : in C# and VB 3 July 14th, 2011 01:01 PM
about ASPNetDB.mdf bela_sush ASP.NET 3.5 Basics 1 October 18th, 2010 12:14 PM
about ASPNetDB.mdf bela_sush BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 2 October 18th, 2010 10:56 AM
aspnetdb.mdf Jackxxx ASP.NET 2.0 Basics 0 January 9th, 2007 01:37 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.