在附加数据库中创建成员资格表、SPROC、视图
我的 VS 2010 项目中有 AdventureWorks 数据库 mdf 文件。无论如何,我可以在 AdventureWorks 数据库中创建会员表吗?我知道我可以在 SQL SERVER 2008 中分离数据库附加。创建表,然后分离。但我没有 SQL SERVER 2008,我想看看是否可以使用命令行工具来完成此操作。
我尝试了此操作,但没有用:
aspnet_regsql.exe -d AdventureWorks.mdf -A mr -E -S .\SQLEXPRESS
更新:
如果我右键单击并查看 AdventureWorks.mdf 数据库的属性,则它显示名称为
“C4BE6C8DA139A060D14925377A7E63D0_64A_10\ADVENTUREWORKSWEBFORMS\ADVENTUREWORKSWEBFORMS\ADVENTUREWORKS\APP_DATA\ADVENTUREWORKS.MDF” “
这很有趣!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为问题在于您试图在独立的 SQLExpress 数据库上执行此操作。您可能拥有实际上永久附加的 AdventureWorks 的另一个副本,这就是您没有看到任何错误的原因。
请尝试以下操作:
1) 如果您还没有 SQL Server Management Studio [Express] 的副本,获取它 - 它比 Visual Studio 更容易使用。
2) 运行以下脚本:
3) 如果您收到一条错误消息,指出数据库不存在,请跳到步骤 5。如果您看到
physical_name
条目与您的中的本地条目不匹配>app_data
文件夹,继续下一步。如果您看到同一个app_data
文件夹中的条目,那么我就被难住了。4) 运行以下命令以分离现有数据库:
5) 运行以下命令以附加应用程序的 SQL Express 数据库:
6) 使用最初使用的相同选项再次运行 aspnet_regsql 工具,但不包含
.mdf
在数据库名称的末尾。7) 在 SSMS[E] 中验证表是否已创建。
8) 使用
EXEC sp_detach_db 'AdventureWorks'
再次分离数据库(如果应用程序依赖于其连接字符串中的临时附件,我打赌它会这样做,则需要执行此操作)。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:
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 yourapp_data
folder, continue to the next step. If you see entries that are in that sameapp_data
folder, then I'm stumped.4) Run the following to detach the existing DB:
5) Run the following to attach the SQL Express DB for your app:
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).运行此命令。将 C:\My Project\APP_DATA\aspnetdb.mdf 替换为 mdf 文件的路径:
Run this command. Replace C:\My Project\APP_DATA\aspnetdb.mdf with the path to your mdf file: