A read-only or failed resolution occurs after SQL Server attaches a database _mssql

Source: Internet
Author: User
Tags win32

Several key points to address this problem are as follows:

1, this phenomenon will only appear in the NTFS file system.

2, by the NTFS file system access permissions caused.

The General manual solution is as follows:

1, Control Panel-> folder Options-> view off "Use Simple File Sharing (recommended)"

2, choose the folder that holds the database file, right key chooses the attribute, at this time will have a more "Security" tab, select the last user, the user's permission set to "Full Control".

After these two steps, the database attach failure or append-only problem can be resolved.

These two steps are focused on the implementation of C # code, because when we package the project, it is impossible for the user to perform these actions manually

1, C # to turn off simple file sharing code implementation
Baidu, Google search for this problem solution, many of the operation method is not correct, after their actual operation test, the correct method is as follows:
Registry file:
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa]
"ForceGuest" =dword:00000000
Batch processing:
REG ADD hklm\system\currentcontrolset\control\lsa/v forceguest/t reg_word/d 0x00000000/f
If selected, the above 0x00000000 is changed to 0x00000001.

Implement the following code by modifying the registry:
Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.LocalMachine;
Microsoft.Win32.RegistryKey software = key. OpenSubKey (@ "SYSTEM\CurrentControlSet\Control\Lsa", true);
Software. SetValue ("ForceGuest", 0);

2. C # Modify the user access rights for the specified folder as follows: (Set the user's permissions to writable)
String path = this. context.parameters["TARGETDIR"];//Get folder path
DirectoryInfo dinfo = new DirectoryInfo (path);
DirectorySecurity dsecurity = Dinfo.getaccesscontrol ();
Dsecurity.addaccessrule (New FileSystemAccessRule (Environment.username, Filesystemrights.createfiles, Accesscontroltype.allow));
Dinfo.setaccesscontrol (dsecurity);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.