Reputation: 20086
I have AdventureWorks database mdf file in my VS 2010 project. Is there anyway I can create Membership tables inside my AdventureWorks database. I know I can detach the database attach in SQL SERVER 2008. Create the tables and then detach. But I don't have SQL SERVER 2008 and I want to see if this can be done using command line tool.
I tried this but no use:
aspnet_regsql.exe -d AdventureWorks.mdf -A mr -E -S .\SQLEXPRESS
Update:
If I right click and see the properties of the AdventureWorks.mdf database then it shows the name as
"C4BE6C8DA139A060D14925377A7E63D0_64A_10\ADVENTUREWORKSWEBFORMS\ADVENTUREWORKSWEBFORMS\ADVENTUREWORKS\APP_DATA\ADVENTUREWORKS.MDF"
This is interesting!
Upvotes: 4
Views: 839
Reputation: 2489
Run this command. Replace C:\My Project\APP_DATA\aspnetdb.mdf with the path to your mdf file:
aspnet_regsql -A all -C "Data Source=.\SQLEXPRESS;Integrated Security=True;User Instance=True" -d "C:\MyProject\APP_DATA\aspnetdb.mdf"
Upvotes: 1
Reputation: 122664
I think the problem is that you're trying to do this on a detached SQLExpress database. You might have another copy of AdventureWorks that's actually permanently attached, which is why you're not seeing any errors.
Please try the following:
1) If you don't already have a copy of SQL Server Management Studio [Express], get it - it'll be easier to work with for this than Visual Studio.
2) Run the following script:
USE AdventureWorks
SELECT name, physical_name
FROM sys.database_files
3) If you get an error that says the database does not exist, skip to step 5. If you see physical_name
entries that don't match the local in your app_data
folder, continue to the next step. If you see entries that are in that same app_data
folder, then I'm stumped.
4) Run the following to detach the existing DB:
EXEC sp_detach_db 'AdventureWorks'
5) Run the following to attach the SQL Express DB for your app:
EXEC sp_attach_db 'AdventureWorks',
'C:\inetpub\wwwroot\MyApp\App_Data\ASPNETDB.MDF',
'C:\inetpub\wwwroot\MyApp\App_Data\ASPNETDB_log.ldf'
6) Run the aspnet_regsql tool again with the same options you used originally, except do not include .mdf
at the end of the database name.
7) Verify in SSMS[E] that the tables were created.
8) Detach the database again with EXEC sp_detach_db 'AdventureWorks'
(you'll need to do this if the app relies on ad-hoc attachment in its connection string, which I'm betting it does).
Upvotes: 1