Connection string with relative path to the database file

后端 未结 10 763
暗喜
暗喜 2020-11-28 07:20

I load data from sdf database in winforms App. I use full path to the database file . Example :

conn = new SqlCeConnection

{

ConnectionString =\"Data Sou         


        
10条回答
  •  猫巷女王i
    2020-11-28 08:11

    Try this code to the working directory if database file exists like below.

    D:\HMProject\DataBase\HMProject.sdf

    string Path = Environment.CurrentDirectory;
    string[] appPath =  Path.Split(new string[] { "bin" }, StringSplitOptions.None);
    AppDomain.CurrentDomain.SetData("DataDirectory", appPath[0]);
    

    Connection string for .sdf file

    Thanks

    ck.Nitin (TinTin)

提交回复
热议问题