在同一台计算机上复制 ASP.NET MVC 网站 - 灾难?

发布于 2024-10-12 22:49:00 字数 921 浏览 5 评论 0原文

我想从同一台计算机运行(使用 Cassini)我的 Web 应用程序的两个副本 - 并非不合理(或者我是这么认为的!)。一个使用端口 80,另一个使用端口 81。所以我执行了以下操作:

  1. 停止 Cassini 和 SQL Express
  2. 复制并粘贴站点根文件夹(并将其重命名)
  3. 打开 Cassini 资源管理器并在端口 81 上设置一个新站点并将其指向复制的位置
  4. 更改了复制站点的 web.config,以便连接字符串使用“Database=NewAlias”,因为 SQL Express 无法附加具有相同别名的两个数据库。
  5. 再次启动 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:

  1. Stopped Cassini and SQL Express
  2. Copy and paste of the site root folder (and renamed it)
  3. Opened Cassini explorer and setup a new site on port 81 and pointed it to the copied location
  4. 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.
  5. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

眼眸 2024-10-19 22:49:00

我不认为你可以通过文件复制实时数据库。如果您先分离它,然后复制它,然后可以重新附加(使用 sp_detach_db) 通过将文件安装为新数据库来实现它。

sp_detach_db OldDb

然后复制该文件夹,然后重新附加(使用 sp_attach_db) 将 db 文件作为新数据库。

sp_attach_db NewDb, "C:\copy of site\App_Data\db_data.mdf", "C:\site1\App_Data\db_log.ldf"

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.

sp_detach_db OldDb

Then copy the folder, then reattach (with sp_attach_db) the db files as a new database.

sp_attach_db NewDb, "C:\copy of site\App_Data\db_data.mdf", "C:\site1\App_Data\db_log.ldf"
暗藏城府 2024-10-19 22:49:00

执行此类操作时有时会出现的另一个大问题(在上面的场景中,错误消息模糊地回避了这一点)是,尽管正在使用复制的 MDF 文件,但它仍然链接到原始 LDF(日志文件) )。您可以运行此命令来获取用于连接实例的文件列表:

sp_helpfile

这将为您提供类似以下内容作为响应:

name    fileid  filename    filegroup   size    maxsize growth  usage   
=========================================================
db  1   C:\site2\App_Data\db.mdf    PRIMARY 24192 KB    Unlimited   1024 KB data only   
db_log  2   C:\site1\App_Data\db_log.ldf        78080 KB    2147483648 KB   10% log only    

您可以从输出中看到日志文件正在与旧数据库共享,这显然会导致问题,因此您可以将其更改为指向复制的日志文件,如下所示:

ALTER DATABASE NewAlias MODIFY FILE (NAME = db_log, FILENAME='c:\site2\App_Data\db_log.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:

sp_helpfile

Which will give you something like this as a response:

name    fileid  filename    filegroup   size    maxsize growth  usage   
=========================================================
db  1   C:\site2\App_Data\db.mdf    PRIMARY 24192 KB    Unlimited   1024 KB data only   
db_log  2   C:\site1\App_Data\db_log.ldf        78080 KB    2147483648 KB   10% log only    

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:

ALTER DATABASE NewAlias MODIFY FILE (NAME = db_log, FILENAME='c:\site2\App_Data\db_log.ldf')
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文