Connection string with relative path to the database file

后端 未结 10 735
暗喜
暗喜 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条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-28 08:00

    Would you please try with below code block, which is exactly what you're looking for:

    SqlConnection conn = new SqlConnection
    {
        ConnectionString = "Data Source=" + System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase) + "\\Database.sdf"
    };
    

提交回复
热议问题