How to detect if SQL Server CE 4.0 is installed

蓝咒 提交于 2019-12-06 05:48:55

问题


I develop some application that needs SQL Server CE 4.0 installed.

I do all job under Windows 7 64-bit so I have installed SQL Server CE 4.0 64-bit.

How I can do some checking if there is installed SQL Server CE 4.0 32-bit/64-bit when I start the application/or installer?

Which is the approach in general?

Any clue, articles and etc?

Thanks!!

P.S. I read this link How can InstallShield check if SQL Server 2005 (3.1) Compact Edition (CE) is installed but it doesn't help.


回答1:


Just include all the required files with your app, and it will run on both x86 and x64 - see my blog post here: http://erikej.blogspot.com/2011/02/using-sql-server-compact-40-with.html

You can also use code below to detect if the runtime is available to your app, but not required if yu implement above:

        public bool IsV40Installed()
    {
        try
        {
            System.Reflection.Assembly.Load("System.Data.SqlServerCe, Version=4.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91");
        }
        catch (System.IO.FileNotFoundException)
        {
            return false;
        }
        try
        {
            var factory = System.Data.Common.DbProviderFactories.GetFactory("System.Data.SqlServerCe.4.0");
        }
        catch (System.Configuration.ConfigurationException)
        {
            return false;
        }
        catch (System.ArgumentException)
        {
            return false;
        }
        return true;
    }


来源:https://stackoverflow.com/questions/10534158/how-to-detect-if-sql-server-ce-4-0-is-installed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!