Reputation: 69
I made a perfect application and I have to make insallation for that app. But i have a localDB and there is my problem, how, and where to store mdf file. I had searched about it on google but I haven't arrived at a solution yet.
I have tried two solutions.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionStrings>
<add name="Test1" connectionString=" Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\Artikli.mdf;Integrated Security=True" providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>
Where other programs store their databases? What is the best way to do it?
Upvotes: 1
Views: 347
Reputation: 513
You should set up your connectionstring programmatically in some special folder in which the user will have access, like this:
string path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\your folder\your app\your database.mdf";
string connectionString = string.Format("Data Source = {0}; Integrated Security = True; providerName = System.Data.SqlClient;", path);
..and when the program starts you should verify if this database is already saved in the specified folder, if not, you can copy the database from installation folder to there.
File.Copy(Application.StartupPath + @"\your database.mdf", Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\your folder\your app\your database.mdf");
Upvotes: 1