本文介绍了无法创建或访问.MDF文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨朋友,



我创建了Windows应用程序,因为我使用的是数据库部分所以我需要提供一个选项来创建选中的.MDF文件使用c#编码中的脚本的路径(用户定义路径)。在这里我面临的问题是''​​无法在c盘中创建.MDF文件'',如果我在其他驱动器(D,E,....)中创建.MDF文件意味着我无法打开文件并抛出访问被拒绝的错误。我已经为创建.MDF文件的路径授予了用户完全权限。



创建.MDF文件的代码是



Hi Friends,

I have created windows application, in that i am using a database part so i need to provide a option to create .MDF file in selected path(user define path) using scripts in c# coding. Here i am facing the problem is ''unable to create the .MDF file in c drive'', if i create .MDF file in some other drive (D,E,....) means i am unable to open the file and throwing a error as "Access is Denied". I have given user full permission for the path where the .MDF file is created.

Code for Creating .MDF file is

string conxString = "Data Source=" + ServerName + ";Initial Catalog=master; Integrated Security=True";

                using (SqlConnection DBCon = new SqlConnection(conxString))
                {
                    DBCon.Open();

                    string str = "CREATE DATABASE " + FileName + " ON PRIMARY " +
                    "(NAME = N" + FileName + " ," +
                    "FILENAME = N'" + FileFullPath + ".mdf', " +
                    "SIZE = 4MB, MAXSIZE = UNLIMITED, FILEGROWTH = 10%) " +
                    "LOG ON (NAME = N" + FileName + "_Log, " +
                    "FILENAME = N'" + FileFullPath + "Log.ldf'," +
                    "SIZE = 2MB, MAXSIZE = 2048GB, FILEGROWTH = 10%)";

                    SqlCommand Cmd = new SqlCommand(str, DBCon);
                    Cmd.ExecuteNonQuery();
                    DBCon.Close();
}


This path and .MDF file name i have stored in app.config (|DataDirectory|\DataBase=.MDF File path) 


<userSettings>
    <DAL.Properties.Settings>
      <setting name="InformerConnectionString" serializeAs="String">
        <value>Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\DataBase\Informer.mdf;Integrated Security=SSPI;User Instance=True</value>
      </setting>
    </DAL.Properties.Settings>
  </userSettings>

from here to i am getting the connection string







感谢Maciej为你的重播,





所以任何人都可以建议我解决这个问题



先谢谢。




Thanks Maciej for your Replay,


So can any one suggest me to fix the issue

Thanks in Advance.

推荐答案


这篇关于无法创建或访问.MDF文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 09:29