简体   繁体   中英

DataBase will not store in selected folder

I am trying to save my database file to a specific folder . I am using the following code to attempt this:

            dpath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);

            AppDomain.CurrentDomain.SetData("DataDirectory", dpath);
            newConnectString = "Data Source=" + dpath + "\\" + filename;

            Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            config.ConnectionStrings.ConnectionStrings[ConnectStringName].ConnectionString = newConnectString;
            config.Save(ConfigurationSaveMode.Modified, true);
            ConfigurationManager.RefreshSection("connectionStrings");

When the program runs, the new file is never created in the destination folder. It is still storing it with the executable . Any insight as to what I might be doing wrong?

您当前的代码只改变了你的配置文件,你还需要将数据库文件File.Copy到所需forlder,或使用SqlCeEngine.CreateDatabase与新的连接字符串。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM