Change ConnectionString to AppData / Roaming

0

My application has installed the .mdf database in AppData / Roaming. Now I need to probably change my path from ConnectionString to this place. How do I do that?

I read on the internet about using Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)

But where do I type this? In% itself with% where is the whole code?

In the file Form1.cs has this code:

connectionString="Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\DatabaseIris.mdf;Integrated Security=True"
    
asked by anonymous 18.08.2017 / 02:26

1 answer

0

Change with relative path (recommended):

    ConnectionString = "Data Source=|DataDirectory|\Database.sdf";

Change at runtime according to executable:

    var executavelAtual = System.Reflection.Assembly.GetExecutingAssembly().Location;
    var diretorioAtual = (System.IO.Path.GetDirectoryName(executable));
    AppDomain.CurrentDomain.SetData("DataDirectory", diretorioAtual);

Source: link

    
18.08.2017 / 09:03