๐Ÿ˜œ

์ญˆ๋‚˜์•„๋น  ๋ธ”๋กœ๊ทธ

JUNA
STUDIO

[MS-SQL] Fixing Orphaned Users After Attaching an MDF/LDF File in SQL Server

๋ฐœํ–‰์ผ: Feb, 2025
์กฐํšŒ์ˆ˜: 1
๋‹จ์–ด์ˆ˜: 152

Table of Contents

Issue Overview

Sometimes, the master database on the C drive may become corrupted or lost, leaving only the MDF and LDF files as backups. When reattaching these database files to a SQL Server instance, you may encounter an issue where the login user in SQL Server does not match the user ID within the attached database. This discrepancy prevents proper access to the database.


Solution

One way to resolve this is by manually deleting the user from the database and remapping it through the SQL Server Management Studio (SSMS) GUI. However, a more efficient approach is to execute a stored procedure to fix the mismatch automatically.


SQL Command

Run the following SQL command to update the login mapping for the database user:

EXEC sp_change_users_login 'Update_One', 'myuser', 'myuser'

This command ensures that the specified login user is correctly mapped to the corresponding database user, resolving any orphaned user issues efficiently.


Tags: #SQL Server#Attach Database#MDF#LDF#sp_change_users_login#Fix Orphaned Users
JUNA BLOG VISITORS
Today
7
 (
updown
-7
)
Total
657
 (
updown
+7
)

ยฉ 2025 juniyunapapa@gmail.com.