Click here to Skip to main content
15,887,585 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
if My Application Executable Path in C:\Program Files then Database Create Code not Work Without any error but If My Application Executable Path in D:\ My Code Work Fine

but in my workplace we have a software which Install in C:\ Program Files and when i delete database from C:\ and open application automatic Create Blank Database

than why i not able create database in C:\

What I have tried:

public static string datafilename = Path.GetDirectoryName(Application.ExecutablePath)+ @"\Data.accdb";

private void Form1_Load(object sender, EventArgs e)
{
CreateDataBase();
}

private void CreateDataBase()
{

if (!File.Exists(datafilename))
{
label1.Text = "DataBase not found";
var cat = new ADOX.Catalog();

cat.Create("Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source="+ datafilename + ";" + "Jet OLEDB:Engine Type=5");
label1.Text = "Database Created Successfully";
cat = null;
createTable();
}
else
{
label1.Text= "Database Found";

}
}
Posted
Updated 23-Oct-20 0:53am

1 solution

You should not use eiteher C:\ or C:\ Program Files for your data storage. Thos locations are protected by Windows. See Where Should I Store My Data?[^].
 
Share this answer
 
Comments
Amar chand123 23-Oct-20 6:58am    
Then how my workplace application create in database in his executable path my workplace application install in Direct C:\ not in C:\Program Files
Richard MacCutchan 23-Oct-20 7:29am    
Please read what I posted above, and use a proper location for your database, and any other data that your application needs access to.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900