在同一台计算机上复制 ASP.NET MVC 网站 - 灾难?
我想从同一台计算机运行(使用 Cassini)我的 Web 应用程序的两个副本 - 并非不合理(或者我是这么认为的!)。一个使用端口 80,另一个使用端口 81。所以我执行了以下操作:
- 停止 Cassini 和 SQL Express
- 复制并粘贴站点根文件夹(并将其重命名)
- 打开 Cassini 资源管理器并在端口 81 上设置一个新站点并将其指向复制的位置
- 更改了复制站点的 web.config,以便连接字符串使用“Database=NewAlias”,因为 SQL Express 无法附加具有相同别名的两个数据库。
- 再次启动 Cassini 和 SQL Express
当我浏览到NEW站点时,出现的第一件事是:
无法打开物理文件 “C:\site1\App_Data\db_log.ldf”。 操作系统错误 32:“32( 进程无法访问该文件,因为 它正在被另一个人使用 进程。)”。无法创建文件 'C:\site2 \App_Data\db_log.LDF' 因为 它已经存在了。更改文件 路径或文件名,然后重试 手术。无法打开数据库 登录请求“NewAlias”。这 登录失败。用户登录失败 'NT 权威\系统'。文件激活 失败。物理文件名 “C:\site1\App_Data\db_log.ldf”可能是 不正确。
它尝试从旧位置打开mdf(即使web.config指定了新位置的确切mdb路径),但尝试在新中创建日志地点。然后最重要的是,删除它无法从 OLD 位置访问 ldf 的提示,或者可能无法登录它。
微软和你的团队再次干得好,犯了一些真正直观的错误!有人可以帮忙吗?
I wanted to run (using Cassini) two copies of my web application from the same computer - not unreasonable (or so I thought!). One using port 80, the other using port 81. So I did the following:
- Stopped Cassini and SQL Express
- Copy and paste of the site root folder (and renamed it)
- Opened Cassini explorer and setup a new site on port 81 and pointed it to the copied location
- Changed the web.config of the copied site so that the connection string used "Database=NewAlias" because SQL Express cant attach two databases with the same alias.
- Started Cassini and SQL Express again
When I browsed to the NEW site, the first thing that comes up is:
Unable to open the physical file
"C:\site1\App_Data\db_log.ldf".
Operating system error 32: "32(The
process cannot access the file because
it is being used by another
process.)". Cannot create file 'C:\site2
\App_Data\db_log.LDF' because
it already exists. Change the file
path or the file name, and retry the
operation. Cannot open database
"NewAlias" requested by the login. The
login failed. Login failed for user
'NT AUTHORITY\SYSTEM'. File activation
failure. The physical file name
"C:\site1\App_Data\db_log.ldf" may be
incorrect.
Its trying to open the mdf from the OLD location (even if the web.config specifies the exact mdb path to the new location) but trying to create a log in the NEW location. Then to top it all off, drops the hint that it cannot access the ldf from the OLD location, or maybe cant log into it.
Well done Microsoft and your team once again for some truly intuitive errors! Can anyone help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不认为你可以通过文件复制实时数据库。如果您先分离它,然后复制它,然后可以重新附加(使用 sp_detach_db) 通过将文件安装为新数据库来实现它。
然后复制该文件夹,然后重新附加(使用 sp_attach_db) 将 db 文件作为新数据库。
I don't think you can just copy a live database via the files. If you detach it first, then copy it, you can then reattach (with sp_detach_db) it by mounting the files as a new database.
Then copy the folder, then reattach (with sp_attach_db) the db files as a new database.
执行此类操作时有时会出现的另一个大问题(在上面的场景中,错误消息模糊地回避了这一点)是,尽管正在使用复制的 MDF 文件,但它仍然链接到原始 LDF(日志文件) )。您可以运行此命令来获取用于连接实例的文件列表:
这将为您提供类似以下内容作为响应:
您可以从输出中看到日志文件正在与旧数据库共享,这显然会导致问题,因此您可以将其更改为指向复制的日志文件,如下所示:
Another big problem that sometimes occurs when doing this kind of thing (and did in the scenario above which is vaguely eluded to by the error message) is that although the copied MDF file is being used, its still linked to the original LDF (log file). You can run this command to get a list of which files are being used for a connected instance:
Which will give you something like this as a response:
You can see from the output that the log file is being shared with the old database which obviously will cause issues, so you can change it to point to the copied log file as follows: