You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用SUBST虚拟D盘创建SQL数据库遇错误3(找不到指定文件)求助

Fixing "Directory Lookup Failed" Error When Creating SQL Database on SUBST Virtual Drive

Let's break down why this is happening and how to fix it—this is a common gotcha with SUBST and Windows services like SQL Server.

The Root Cause

When you use SUBST to create a virtual drive, that mapping is only visible in your current user session. But SQL Server runs in Session 0, a separate non-interactive session used by Windows services. That means the SQL Server process can't see your SUBST-created D:\ at all, hence the "system cannot find the file specified" error—even if you set permissions correctly on the underlying folder.

Solutions to Try

1. Use a System-Wide Mount (Replace SUBST with mountvol)

Instead of SUBST, use the mountvol command to create a persistent, system-level mount point. This will be visible to all sessions, including Session 0 where SQL Server runs.

Run Command Prompt as Administrator and execute:

mountvol D: C:\Your\Actual\Physical\Directory\Path

Replace C:\Your\Actual\Physical\Directory\Path with the real folder you're mapping to. To remove the mount later, use mountvol D: /D.

2. Test with the Physical Path First

Rule out any permission issues by creating the database directly using the physical folder path instead of the virtual drive. Run this SQL query:

CREATE DATABASE YourDBName
ON PRIMARY (NAME = YourDB_Data, FILENAME = 'C:\Your\Actual\Physical\Directory\Path\YourDB.mdf')
LOG ON (NAME = YourDB_Log, FILENAME = 'C:\Your\Actual\Physical\Directory\Path\YourDB.ldf');

If this works, you can confirm the problem is definitely the SUBST drive's session visibility, not permissions.

3. Double-Check Permissions on the Physical Folder

Even though you granted full access, make sure you applied the permissions correctly:

  • Navigate to the actual physical folder (not the virtual D:), right-click > Properties > Security tab.
  • Add the SQL Server service account (usually NT SERVICE\MSSQLSERVER if it's the default instance) and grant it Full Control over the folder and all subobjects.
  • Click "Advanced" to verify the permission is inherited by child items and applied correctly.

4. Avoid SUBST for SQL Server Paths

SUBST is great for user-level shortcuts, but it's not reliable for services that run in separate sessions. Stick to physical paths or system-level mounts with mountvol when working with SQL Server data files.

内容的提问来源于stack exchange,提问作者Amarnath

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 12:25:25