错误附加数据库(.mdf文件)到SQL Server [英] Error attaching a database (.mdf file) to SQL Server
问题描述
我有麻烦的数据库 DBName.mdf
连接到网络上的SQL Server。管理员可以手动附加数据库,但如果我尝试,我得到以下错误消息。
I'm having trouble attaching a database DBName.mdf
to a network SQL Server. The admin can manually attach the database but if I try, I get the following error message.
数据库'数据库名'不能升级,因为它是只读的,具有只读文件或者用户没有权限修改一些文件。使数据库或文件可写,然后重新运行恢复。 (微软SQL Server,错误:3415)
Database 'DBName' cannot be upgraded because it is read-only, has read-only files or the user does not have permissions to modify some of the files. Make the database or files writeable, and rerun recovery. (Microsoft SQL Server, Error: 3415)
下面是我的代码:
System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection();
conn.ConnectionString = @"Server=" + SQLServerName + ";database=master;User ID=" + UserName + ";Pwd=" + Password; ;
try
{
conn.Open();
System.Data.SqlClient.SqlCommand com = new System.Data.SqlClient.SqlCommand("CREATE DATABASE DBName ON ( FILENAME = '" + @"C:\DBName.mdf" + "' ), ( FILENAME = '" + @"C:\DBName_log.ldf" + "' ) FOR ATTACH", conn);
com.ExecuteScalar();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
conn.Close();
}
下面是SQL Server的细节
Here is the details of SQL Server
- Product - Microsoft SQL Server Express Edition (64-bit)
- Version - 11.0.2218.0
我可以创建一个新的数据库得很好,但不能将现有的数据库。缺少什么我在这里?
任何帮助将不胜感激。
推荐答案
我想通了什么问题了。
这个联系是搞清楚这个问题有帮助。
http://www.sqlservercentral.com/Forums/FindPost1367859.aspx
This link was helpful in figuring out the problem. http://www.sqlservercentral.com/Forums/FindPost1367859.aspx
在其下SQL服务正在运行并没有完全访问权限到该文件夹的用户。我给用户完全权限,一切工作正常。
The user under which the SQL Service was running didn't have full access permissions to that folder. I gave the user full permission and everything worked fine.
这篇关于错误附加数据库(.mdf文件)到SQL Server的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!