Creation of membership tables, SPROC, views in the attached database

I have an AdventureWorks mdf file in my VS 2010 project. In any case, I can create membership tables inside my AdventureWorks database. I know that I can separate a database application in SQL SERVER 2008. Create tables and then detach. But I do not have SQL SERVER 2008, and I want to see if this can be done using the command line tool.

I tried this but not used:

aspnet_regsql.exe -d AdventureWorks.mdf -A mr -E -S .\SQLEXPRESS 

Update:

If I right-click and look at the database properties of AdventureWorks.mdf, then it will display the name as

"C4BE6C8DA139A060D14925377A7E63D0_64A_10 \ ADVENTUREWORKSWEBFORMS \ ADVENTUREWORKSWEBFORMS \ ADVENTUREWORKS \ APP_DATA \ ADVENTUREWORKS.MDF"

It is interesting!

+4
source share
2 answers

I think the problem is that you are trying to do this in a separate SQLExpress database. You may have another copy of AdventureWorks that is actually permanently attached, so you don't see any errors.

Try the following:

1) If you do not already have a copy of SQL Server Management Studio [Express], getting it will be easier to work with than with Visual Studio.

2) Run the following script:

 USE AdventureWorks SELECT name, physical_name FROM sys.database_files 

3) If you receive an error message indicating that the database does not exist, go to step 5. If you see physical_name entries that do not match the local one in your app_data folder, go to the next step. If you see entries that are in the same app_data folder, then I am puzzled.

4) To disconnect an existing database, follow these steps:

 EXEC sp_detach_db 'AdventureWorks' 

5) To attach SQL Express DB for your application, do the following:

 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 parameters that you originally used, except that do not include .mdf at the end of the database .mdf .

7) Verify in SSMS [E] that the tables have been created.

8) EXEC sp_detach_db 'AdventureWorks' database again using EXEC sp_detach_db 'AdventureWorks' (you will need to do this if the application uses ad-hoc attachment in its connection string, which I’m bidding on).

+1
source

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" 
+1
source

Source: https://habr.com/ru/post/1307362/


All Articles