How to detect if SQL Server CE 4.0 is installed

2019-04-10 05:20发布

问题:

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;
    }