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
Thanks Maciej for your Replay,
So can any one suggest me to fix the issue
Thanks in Advance.